Nestharus
o-o
- Reaction score
- 83
Code:
//------------------------------------------------------------------------------------------------------------------------------------------------------
//
// *************************************************************
// * *
// * Dynamic Memory Allocator *
// * *
// * v1.1.1.2 *
// * ~Nestharus *
// * *
// *************************************************************
//
//------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Details
//
// Heap memory allocation in order to declare arrays on the fly. Also includes memory display functions.
//
//------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Memory Types
//
// see script
//
//------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Pointer Functions
//
// see script
//
//------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Memory arrays
//
// see script
//
//------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Memory Functions
//
// see script
//
//------------------------------------------------------------------------------------------------------------------------------------------------------
//
// System Functions
//
// see script
//
//------------------------------------------------------------------------------------------------------------------------------------------------------
Code:
void print(string msg) {
TriggerDebugOutput(1, StringToText(msg), true);
}
void displayMemory(int memoryType) {
printMemoryRemaining(memoryType);
printMemoryUsed(memoryType);
printMemoryUsedPercent(memoryType);
}
void test() {
const int TEST_SIZE = 50;
int[TEST_SIZE] arr;
int i = 0;
while (i != TEST_SIZE) {
arr[i] = allocate(RandomInt(15, 35), MEMORY_TYPE_INT);
i = i + 1;
} //while
displayMemory(MEMORY_TYPE_INT);
printHeapSize(MEMORY_TYPE_INT);
print("-----------------------------");
deallocate(arr[22]);
deallocate(arr[24]);
deallocate(arr[23]);
deallocate(arr[21]);
deallocate(arr[21]);
deallocate(294282);
displayMemory(MEMORY_TYPE_INT);
printHeapSize(MEMORY_TYPE_INT);
print("Test Complete");
}
void tester() {
initializeMemoryAllocation();
test();
}
Attachments
-
7.9 KB Views: 384