ClearStructure(..., ..., #PB_Structure_ClearNested)
Posted: Mon Jul 26, 2010 12:05 pm
Hi,
just updating some code to use some of the new features (PB 4.5), in particular discarding some code for clearing dynamic structures in favour of the new ClearStructure() etc.
Came across some nested structure pointers in which it would be nice (
) if ClearStructure() could be persuaded to do it all for me in one swoop!
Take the following structure for example :
And the following code which allocates two chunks of memory, one for a 'test' structure and one for a STRING structure :
Now as things stand, the only way of tidying this memory up is via two calls to ClearStructure() as follows :
No great hardship I admit.
I was just wondering, however, if it would be viable to add some optional parameter to ClearStructure() so that it could run through and clear both structures in one go? I would then be able to replace my two previous calls to ClearStructure() with something like :
With this optional parameter specified, all pointers to structures (of explicit types) could be tidied up by PB in some recursive manner. Course this would have to be used with great care and would only be useable if all such structure pointers pointed to some dynamically allocated memory rather than some global/static structure etc, but in my case that is invariably the case anyhow! 
Thanks.
just updating some code to use some of the new features (PB 4.5), in particular discarding some code for clearing dynamic structures in favour of the new ClearStructure() etc.
Came across some nested structure pointers in which it would be nice (

Take the following structure for example :
Code: Select all
Structure test
a$
*ptrString.STRING
EndStructure
Code: Select all
*ptr.test = AllocateMemory(SizeOf(test))
If *ptr
*ptr\a$ = "Hello matey!"
*ptr\ptrString = AllocateMemory(SizeOf(STRING))
If *ptr\ptrString
*ptr\ptrString\s = "Hello again!"
EndIf
EndIf
Code: Select all
ClearStructure(*ptr\ptrString, STRING)
ClearStructure(*ptr, test)

I was just wondering, however, if it would be viable to add some optional parameter to ClearStructure() so that it could run through and clear both structures in one go? I would then be able to replace my two previous calls to ClearStructure() with something like :
Code: Select all
ClearStructure(*ptr, test, #PB_Structure_ClearNested)

Thanks.