GADGET-4
|
Manager for dynamic memory allocation. More...
#include "gadgetconfig.h"
#include <fcntl.h>
#include <math.h>
#include <mpi.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../data/allvars.h"
#include "../data/dtypes.h"
#include "../data/mymalloc.h"
#include "../logs/logs.h"
#include "../main/simulation.h"
#include "../mpi_utils/mpi_utils.h"
#include "../mpi_utils/shared_mem_handler.h"
#include "../system/system.h"
Go to the source code of this file.
Manager for dynamic memory allocation.
This module handles the dynamic memory allocation. To avoid memory allocation/dellocation overhead a big chunk of memory (which will be the maximum amount of dinamically allocatable memory) is allocated upon initialization. This chunk is then filled by the memory blocks as in a stack structure. The blocks are automatically aligned to a CACHELINESIZE bit boundary. Memory blocks come in two flavours: movable and non-movable. In non-movable blocks the starting address is fixed once the block is allocated and cannot be changed. Due to the stack structure of the dynamic memory, this implies that the last (non-movable) block allocated must be the first block to be deallocated. If this condition is not met, an abort condition is triggered. If more flexibility is needed, movable memory blocks can be used. In this case, the starting address of the block is again fixed upon allocation but the block can be shifted (therefore its initial address changes) according to needs. For a movable block to be successfully shifted it is required that all the subsequent allocated blocks are movable. Again, an abort condition is triggered if this condition is not met. Movable blocks can be deallocated in any order provided that the condition just described holds. The gap resulting form the deallocation of a block that is not in the last position will be automatically filled by shifting all the blocks coming after the deallocated block.
Definition in file mymalloc.cc.