System Dynamic Memory Allocator

Nestharus

o-o
Reaction score
84
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
//
//------------------------------------------------------------------------------------------------------------------------------------------------------

Demonstration
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

  • allocate.zip
    7.9 KB · Views: 467
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top