AllocateStructure() / FreeStructure()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

AllocateStructure() / FreeStructure()

Post 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