/usr/include/freehdl/std-memory.hh is in libfreehdl0-dev 0.0.8-2.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #ifndef FREEHDL_STD_MEMORY_H
#define FREEHDL_STD_MEMORY_H
#include <stdlib.h>
/* *************************************************************
* Memory management for dynamically sized objects
* ************************************************************* */
// Max memory allocation size handled by this routine
#define MAX_INTERNAL_ALLOC_SIZE 1024
// This array stores all currently unused memory chunks.
extern void *mem_chunks[MAX_INTERNAL_ALLOC_SIZE + 1];
// Allocates new memory of size "size". To speedup memory allocation a
// list of unused memory chunks is stored in an array which is
// addressed by size. However, memory chunks of size greater than
// MAX_INTERNAL_ALLOC_SIZE are allocated and freed as usual.
inline void *
internal_dynamic_alloc(unsigned int size)
{
void *result = NULL;
// Memory chunks of size greater than MAX_INTERNAL_ALLOC_SIZE are
// handled as usual
if (size > MAX_INTERNAL_ALLOC_SIZE)
result = malloc(size);
else if (mem_chunks[size] != NULL) {
// If there is a memory chunk of appropriate size then return it.
result = mem_chunks[size];
mem_chunks[size] = *(void**)mem_chunks[size];
} else
// If no unused memory chunk could be found then allocate new
// memory
result = malloc(size >= sizeof(void*)? size : sizeof(void*));
return result;
}
// Free memory. However, memory of size less than or equal to
// MAX_INTENAL_ALLOCA_SIZE is stored into the internal list of unused
// chunks
inline void
internal_dynamic_remove(void *pointer, int size)
{
if (pointer == NULL)
return;
if (size > MAX_INTERNAL_ALLOC_SIZE)
free(pointer);
else {
*(void**)pointer = mem_chunks[size];
mem_chunks[size] = pointer;
}
}
// Free all memory stored in the internal list.
void
internal_dynamic_clean();
#endif
|