How to allocate memory from a specific region

Usually, the functions mallocand freecan be used to allocate memory in accordance with the implementation. However, it is often necessary to manage the allocation of memory from a particular region. Examples include:

  • Shared memory between processes
  • Memory mapped files
  • Non-volatile memory

Instead of writing a one-time implementation of the heap every time this requirement arises, is there a way to reuse it mallocto manage these regions (Linux)? Otherwise, can any of the “known” memory allocators (for example, dmalloc, ptmalloc, etc.) support allocation from a specific area?

Example:

void *pool = mmap(/* my file */);
void *pool_manager = mallloc_init(pool, /* size */);
void *p = malloc_ex(pool, 1024);
free_ex(pool, p);
+7
source
1

, . malloc, - .

, , .

, , , , , , , ).

, . , , , , , , , . , , , , , .

, , NVRAM, . , - , , , , .

, , . ; , . , . - , , , .

0

Source: https://habr.com/ru/post/1693208/


All Articles