buflib: Add a define telling the per-alloc overhead.
This allows buflib clients to more accurately estimate the total memory usage. It's still not 100% accurate because the handle table grows in blocks, thus buflib might use more memory that caused by allocations directly. Change-Id: I68338bb94f510ad188fcb588aebf895b5f9197c5
This commit is contained in:
parent
4ce1deacfd
commit
4ce39f7e73
2 changed files with 13 additions and 0 deletions
|
@ -55,6 +55,8 @@
|
||||||
* to find the start of the character array (and therefore the start of the
|
* to find the start of the character array (and therefore the start of the
|
||||||
* entire block) when only the handle or payload start is known.
|
* entire block) when only the handle or payload start is known.
|
||||||
*
|
*
|
||||||
|
* UPDATE BUFLIB_ALLOC_OVERHEAD (buflib.h) WHEN THIS COOKIE CHANGES!
|
||||||
|
*
|
||||||
* Example:
|
* Example:
|
||||||
* |<- alloc block #1 ->|<- unalloc block ->|<- alloc block #2 ->|<-handle table->|
|
* |<- alloc block #1 ->|<- unalloc block ->|<- alloc block #2 ->|<-handle table->|
|
||||||
* |L|H|C|cccc|L2|crc|XXXXXX|-L|YYYYYYYYYYYYYYYY|L|H|C|cc|L2|crc|XXXXXXXXXXXXX|AAA|
|
* |L|H|C|cccc|L2|crc|XXXXXX|-L|YYYYYYYYYYYYYYYY|L|H|C|cc|L2|crc|XXXXXXXXXXXXX|AAA|
|
||||||
|
|
|
@ -53,6 +53,17 @@ struct buflib_context
|
||||||
bool compact;
|
bool compact;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This declares the minimal overhead that is required per alloc. These
|
||||||
|
* are bytes that are allocated from the context's pool in addition
|
||||||
|
* to the actually requested number of bytes.
|
||||||
|
*
|
||||||
|
* The total number of bytes consumed by an allocation is
|
||||||
|
* BUFLIB_ALLOC_OVERHEAD + requested bytes + strlen(<name passed to
|
||||||
|
* buflib_alloc_ex()) + pad to pointer size
|
||||||
|
*/
|
||||||
|
#define BUFLIB_ALLOC_OVERHEAD (6*sizeof(union buflib_data))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callbacks used by the buflib to inform allocation that compaction
|
* Callbacks used by the buflib to inform allocation that compaction
|
||||||
* is happening (before data is moved)
|
* is happening (before data is moved)
|
||||||
|
|
Loading…
Reference in a new issue