Page 1 of 1

AllocateStructure() / FreeStructure()

Posted: Fri Sep 17, 2010 2:23 pm
by Trond
Some convenience functions would be nice to have:

Code: Select all

AllocateStructure(Typename) =
*P = AllocateMemory(SizeOf(TypeName))
InitializeStructure(*P, TypeName)
Return P

Code: Select all

FreeStructure(*P, Typename) =
ClearStructure(*P, TypeName)
FreeMemory(*P)
If not, a simpler change, is to make InitializeStructure() return the pointer address it was given. We can then make our own macro:

Code: Select all

Macro AllocateStructure(Typename)
  InitializeStructure(AllocateMemory(SizeOf(Typename)), Typename)
EndMacro