#include "String.hpp"
Go to the source code of this file.
Macros | |
#define | Memory__new(Type, from) ((Type)Memory__allocate(sizeof(*((Type)0)), from)) |
Allocate a Type object from the heap. More... | |
Typedefs | |
typedef void * | Memory |
Memory is a pointer to memory. More... | |
Functions | |
Memory | Memory__allocate (unsigned int bytes, String_Const from) |
Allocates bytes of memory and returns a pointer to it. More... | |
void | Memory__free (Memory memory) |
Releases the storage associated with memory. More... | |
#define Memory__new | ( | Type, | |
from | |||
) | ((Type)Memory__allocate(sizeof(*((Type)0)), from)) |
Allocate a Type object from the heap.
The type must be a pointer type where the underlying type defintion is available to the compiler.
This allocates an object of type Type by doing "Memory_new(Type)". This macro when expanded works as follows:
Type zilch = (Type)0; Uint type_size = sizeof(*zilch); Type type = (Type)Memory_allocate(type_size);
"sizeof(*((Type)0))" does not generate any code. The compiler evaluates it to get the number of bytes associated with "Type":
Definition at line 23 of file Memory.hpp.
typedef void* Memory |
Memory is a pointer to memory.
Definition at line 27 of file Memory.hpp.
Memory Memory__allocate | ( | unsigned int | bytes, |
String_Const | from | ||
) |
Allocates bytes of memory and returns a pointer to it.
bytes | is the number of bytes to allocate. |
from | is a debugging string. |
Memory__allocate() will allocated and return a pointer to a chunk of bytes memory.
Definition at line 22 of file Memory.cpp.
void Memory__free | ( | Memory | memory | ) |
Releases the storage associated with memory.
memory | to release. |
Memory__free() will release the storage associated with memory.
Definition at line 60 of file Memory.cpp.