From Vincent Mahnke, 11 Years ago, written in C++.
Embed
  1. // memorybuffer.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "memory.h"
  6. #include "stdlib.h"
  7.  
  8. class MemoryBuffer {
  9. public:
  10.         MemoryBuffer(MemoryBuffer* source);
  11.         MemoryBuffer(unsigned int alocatedSize);
  12.         ~MemoryBuffer();
  13.  
  14.         void* GetBuffer();
  15.         unsigned int GetSize();
  16.        
  17.         unsigned int AlocatedSize;
  18.  
  19. private:
  20.         void* MemoryPointer;
  21. };
  22.  
  23. MemoryBuffer::MemoryBuffer(MemoryBuffer* source) {
  24.  
  25. }
  26.  
  27. void* MemoryBuffer::GetBuffer() {
  28.         return MemoryPointer;
  29. }
  30.  
  31. unsigned int MemoryBuffer::GetSize() {
  32.         return AlocatedSize;
  33. }
  34.  
  35. MemoryBuffer::MemoryBuffer(unsigned int alocatedSize) {
  36.         AlocatedSize = alocatedSize;
  37.         MemoryPointer = calloc(alocatedSize, 1);
  38.         if (MemoryPointer == nullptr) {
  39.                 throw "Out of Memory";
  40.         }
  41. };
  42.  
  43. MemoryBuffer::~MemoryBuffer() {
  44.         free(MemoryPointer);
  45.  
  46.         AlocatedSize = 0;
  47.         MemoryPointer = 0;
  48. }
  49.  
  50. int _tmain(int argc, _TCHAR* argv[])
  51. {
  52.         try {
  53.                 MemoryBuffer mBuffer(16);
  54.                 memset(mBuffer.GetBuffer(), 0, mBuffer.GetSize());
  55.         }
  56.         catch (char* errMsg) {
  57.                        
  58.         }
  59.         return 0;
  60. }
  61.