Game Development Community

Differences between "datablock" and "new"

by Edoardo · in Torque Game Builder · 06/14/2010 (5:35 am) · 3 replies

What is the difference in using :

datablock AudioProfile( PepperPickupSound ) //<---- USING DATABLOCK
{
    filename    = "~/data/audio/general/pepper_pickup.wav";
    description = "SoundOnce";
    preload     = true;
};
and
new AudioProfile( PepperPickupSound ) //<------ USING OPERATOR NEW
{
    filename    = "~/data/audio/general/pepper_pickup.wav";
    description = "SoundOnce";
    preload     = true;
};

#1
06/14/2010 (11:16 pm)
My understanding from here (and somebody correct me if I'm wrong) is that if your code comes across the datablock statement again, nothing will happen. It acts like a singleton and only one will exist in your program.

If you use "new" and it gets executed twice, you will have two objects. And very likely, you'll have leaked a little bit of memory because nobody knows about the first instance anymore.

In this specific case, you've probably got your audio profile defined somewhere where it will only ever be executed once, so you are safe with new.
#2
06/15/2010 (1:26 am)
Thanks William for your explanation...

I've implementend into engine this fix : www.torquepowered.com/community/forums/viewthread/96713

But if I use only datablocks the fix work correctly? can I delete datablocks to release buffer memory?
#3
06/15/2010 (8:04 am)
Scanning through the TorqueScript parser, I think you can still delete classes created with the datablock keyword.

I have an idea for a quick test you can run. After you program has started. Type the following into the console:
echo( isObject( PepperPickupSound ) ); // should return 1
PepperPickupSound.delete();
echo( isObject( PepperPickupSound ) ); // should return 0