#include "allheaders.h"
Go to the source code of this file.
Custom memory storage with allocator and deallocator
l_int32 pmsCreate()
void pmsDestroy()
void *pmsCustomAlloc()
void pmsCustomDealloc()
void *pmsGetAlloc()
l_int32 pmsGetLevelForAlloc()
l_int32 pmsGetLevelForDealloc()
void pmsLogInfo()
Definition in file pixalloc.c.
◆ pmsCreate()
l_ok pmsCreate |
( |
size_t |
minsize, |
|
|
size_t |
smallest, |
|
|
NUMA * |
numalloc, |
|
|
const char * |
logfile |
|
) |
| |
pmsCreate()
- Parameters
-
[in] | minsize | of data chunk that can be supplied by pms |
[in] | smallest | bytes of the smallest pre-allocated data chunk. |
[in] | numalloc | array with the number of data chunks for each size that are in the memory store |
[in] | logfile | use for debugging; null otherwise |
- Returns
- 0 if OK, 1 on error
Notes:
(1) This computes the size of the block of memory required
and allocates it. Each chunk starts on a 32-bit word boundary.
The chunk sizes are in powers of 2, starting at smallest,
and the number of levels and chunks at each level is
specified by numalloc.
(2) This is intended to manage the image data for a small number
of relatively large pix. The system malloc is expected to
handle very large numbers of small chunks efficiently.
(3) Important: set the allocators and call this function
before any pix have been allocated. Destroy all the pix
in the normal way before calling pmsDestroy().
(4) The pms struct is stored in a static global, so this function
is not thread-safe. When used, there must be only one thread
per process.
Definition at line 172 of file pixalloc.c.
References PixMemoryStore::baseptr, PixMemoryStore::firstptr, PixMemoryStore::nbytes, PixMemoryStore::nlevels, numaGetSum(), PixMemoryStore::paa, and PixMemoryStore::sizes.
◆ pmsCustomAlloc()
void* pmsCustomAlloc |
( |
size_t |
nbytes | ) |
|
pmsCustomAlloc()
- Parameters
-
[in] | nbytes | min number of bytes in the chunk to be retrieved |
- Returns
- data ptr to chunk
Notes:
(1) This attempts to find a suitable pre-allocated chunk.
If not found, it dynamically allocates the chunk.
(2) If logging is turned on, the allocations that are not taken
from the memory store, and are at least as large as the
minimum size the store can handle, are logged to file.
Definition at line 310 of file pixalloc.c.
◆ pmsCustomDealloc()
void pmsCustomDealloc |
( |
void * |
data | ) |
|
◆ pmsDestroy()
pmsDestroy()
Notes:
(1) Important: call this function at the end of the program, after
the last pix has been destroyed.
Definition at line 267 of file pixalloc.c.
◆ pmsGetAlloc()
void* pmsGetAlloc |
( |
size_t |
nbytes | ) |
|
pmsGetAlloc()
- Parameters
-
- Returns
- data
Notes:
(1) This is called when a request for pix data cannot be
obtained from the preallocated memory store. After use it
is freed like normal memory.
(2) If logging is on, only write out allocs that are as large as
the minimum size handled by the memory store.
(3) The C99 platform-independent format specifier for size_t is zu.
Windows since at least VC-2015 is conforming; we can now use zu.
Definition at line 397 of file pixalloc.c.
◆ pmsGetLevelForAlloc()
l_ok pmsGetLevelForAlloc |
( |
size_t |
nbytes, |
|
|
l_int32 * |
plevel |
|
) |
| |
pmsGetLevelForAlloc()
- Parameters
-
[in] | nbytes | min number of bytes in the chunk to be retrieved |
[out] | plevel | -1 if either too small or too large |
- Returns
- 0 if OK, 1 on error
Definition at line 428 of file pixalloc.c.
◆ pmsGetLevelForDealloc()
l_ok pmsGetLevelForDealloc |
( |
void * |
data, |
|
|
l_int32 * |
plevel |
|
) |
| |
pmsGetLevelForDealloc()
- Parameters
-
[in] | data | ptr to memory chunk |
[out] | plevel | level in memory store; -1 if allocated outside the store |
- Returns
- 0 if OK, 1 on error
Definition at line 465 of file pixalloc.c.