GSI Forum
GSI Helmholtzzentrum für Schwerionenforschung

Home » PANDA » PandaRoot » Bugs, Fixes, Releases » Question about using pointers to fill TClonesArray
Re: Question about using pointers to fill TClonesArray [message #17682 is a reply to message #17681] Thu, 18 December 2014 21:46 Go to previous messageGo to previous message
Tobias Stockmanns is currently offline  Tobias Stockmanns
Messages: 489
Registered: May 2007
first-grade participant
From: *netcologne.de
Dear Klaus,

the TClonesArray operates as you said. They allocate a block of memory which is dynamically extended if more storage is needed but never freed. If the TClonesArray is cleared the memory is internally marked as free. New data is then written into the same position as the previous data without the need to allocate new memory.

This only works if all objects in the TClonesArray have the same size which does not work for objects with container classes inside. For this purpose the TClonesArray uses a trick. It stores a pointer to the container classes while the data of the container classes are stored outside the memory block of the TClonesArray.

If you call a clear() for a TClonesArray with containers inside you get a memory leak only delete() calls the destructor of the container class which frees the memory of the container.

As I said, it is a bit tricky and it took me a while to figure it out.

Cheers,

Tobias
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [FIXED] fts/FtsTracking/PndFtsHoughSpace.h::ExportTH2S() declared but not implemented
Next Topic: [FIXED] Memory leak in PndSttHitProducerRealFull / PndFtsHitProducerRealFull?
Goto Forum:
  


Current Time: Thu Oct 03 18:06:19 CEST 2024

Total time taken to generate the page: 0.00782 seconds