1 #ifndef VIRTMEM_ALLOC_H
2 #define VIRTMEM_ALLOC_H
15 template <
typename,
typename>
class VPtr;
27 template <
typename Properties,
typename Derived>
30 LockPage smallPagesData[Properties::smallPageCount];
31 LockPage mediumPagesData[Properties::mediumPageCount];
32 LockPage bigPagesData[Properties::bigPageCount];
34 uint8_t smallPagePool[Properties::smallPageCount * Properties::smallPageSize] __attribute__ ((aligned (
sizeof(TAlign))));
35 uint8_t mediumPagePool[Properties::mediumPageCount * Properties::mediumPageSize] __attribute__ ((aligned (
sizeof(TAlign))));
36 uint8_t bigPagePool[Properties::bigPageCount * Properties::bigPageSize] __attribute__ ((aligned (
sizeof(TAlign))));
38 uint8_t smallPagePool[Properties::smallPageCount * (Properties::smallPageSize + valgrindPad * 2)];
39 uint8_t mediumPagePool[Properties::mediumPageCount * (Properties::mediumPageSize + valgrindPad * 2)];
40 uint8_t bigPagePool[Properties::bigPageCount * (Properties::bigPageSize + valgrindPad * 2)];
50 initSmallPages(smallPagesData, &smallPagePool[0], Properties::smallPageCount, Properties::smallPageSize);
51 initMediumPages(mediumPagesData, &mediumPagePool[0], Properties::mediumPageCount, Properties::mediumPageSize);
52 initBigPages(bigPagesData, &bigPagePool[0], Properties::bigPageCount, Properties::bigPageSize);
54 initSmallPages(smallPagesData, &smallPagePool[pad], Properties::smallPageCount, Properties::smallPageSize);
55 initMediumPages(mediumPagesData, &mediumPagePool[pad], Properties::mediumPageCount, Properties::mediumPageSize);
56 initBigPages(bigPagesData, &bigPagePool[pad], Properties::bigPageCount, Properties::bigPageSize);
57 VALGRIND_MAKE_MEM_NOACCESS(&smallPagePool[0], pad); VALGRIND_MAKE_MEM_NOACCESS(&smallPagePool[Properties::smallPageCount * Properties::smallPageSize + pad], pad);
58 VALGRIND_MAKE_MEM_NOACCESS(&mediumPagePool[0], pad); VALGRIND_MAKE_MEM_NOACCESS(&mediumPagePool[Properties::mediumPageCount * Properties::mediumPageSize + pad], pad);
59 VALGRIND_MAKE_MEM_NOACCESS(&bigPagePool[0], pad); VALGRIND_MAKE_MEM_NOACCESS(&bigPagePool[Properties::bigPageCount * Properties::bigPageSize + pad], pad);
62 ~
VAlloc(
void) { instance = 0; }
171 new (
read(p + (s *
sizeof(T)),
sizeof(T))) T;
192 T *ptr =
static_cast<T *
>(
read(p.
getRawNum() + (s *
sizeof(T)),
sizeof(T)));
225 template <
typename Properties,
typename Derived>
230 #endif // VIRTMEM_ALLOC_H
contains all code from virtmem
Definition: base_alloc.cpp:22
Base template class for virtual memory allocators.
Definition: alloc.h:28
PtrNum getRawNum(void) const
Returns a numeric representation of this virtual pointer.
Definition: base_vptr.h:153
void write(VPtrNum p, const void *d, VPtrSize size)
Writes a piece of raw data to (virtual) memory.
Definition: base_alloc.cpp:770
This header file contains several variables that can be used to customize virtmem.
void setRawNum(PtrNum p)
Sets a virtual pointer from a numeric value.
Definition: base_vptr.h:159
VPtrNum allocRaw(VPtrSize size)
Allocates a piece of raw (virtual) memory.
Definition: base_alloc.cpp:560
void freeRaw(VPtrNum ptr)
Frees a memory block for re-usage.
Definition: base_alloc.cpp:647
Base class for virtual memory allocators.
Definition: base_alloc.h:31
VPtr< T, Derived > newClass(VPtrSize size=sizeof(T))
Allocates memory and constructs data type.
Definition: alloc.h:129
uint32_t VPtrNum
Numeric type used to store raw virtual pointer addresses.
Definition: base_alloc.h:21
This header contains the class definition of the VPtr class.
uint32_t VPtrSize
Numeric type used to store the size of a virtual memory block.
Definition: base_alloc.h:22
void free(VPtr< T, Derived > &p)
Frees a block of virtual memory.
Definition: alloc.h:110
Base virtual memory class header.
VPtr< T, Derived > alloc(VPtrSize size=sizeof(T))
Allocates memory from the linked virtual memory allocator.
Definition: alloc.h:96
void deleteArray(VPtr< T, Derived > &p)
Destructs and frees an array of objects.
Definition: alloc.h:186
VPtr< T, Derived > newArray(VPtrSize elements)
Allocates and constructs an array of objects.
Definition: alloc.h:165
void deleteClass(VPtr< T, Derived > &p)
Destructs data type and frees memory.
Definition: alloc.h:146
Generalized shortcut to virtual pointer type linked to this allocator.
Definition: alloc.h:209
Virtual pointer class that provides an interface to access virtual much like 'regular pointers'...
Definition: alloc.h:15
void * read(VPtrNum p, VPtrSize size)
Reads a raw block of (virtual) memory.
Definition: base_alloc.cpp:724
static VAlloc * getInstance(void)
Returns a pointer to the instance of the class.
Definition: alloc.h:79