Problem with DcmFileFormat::clone()
Moderator: Moderator Team
Problem with DcmFileFormat::clone()
Hi,
I have a problem copying DcmFileFormat objects. The problem is kind of difficult to explain:
- my app has a plugin architecture, a la photoshop
- the image loading code is in a plugin (a dll)
- the dll loads an image file DcmFileFormat::loadFile()
- it then passes the DcmFileFormat object to a COM library (another dll)
- that dll copies the DcmFileFormat (because it needs to hang on to it)
Then all kinds of memory related problems occur when I try to manipulate the copied DcmFileFormat object. AFAICT, it seems that portions of the deep copy are not deep copied, thus resulting in heap errors. I tried the clone() method, and the copyFrom() method, and both exhibit the problem.
If I serialize the DcmFileFormat object between the two spaces, then all is good (which would seem to confirm my theory). The problem with that approach is that serialization is very slow (especially de-serialization).
I'm using a 3.6.1 July 27th 2012 snapshot.
How can I solve this issue? Does this ring a bell with anyone?
Thanks
I have a problem copying DcmFileFormat objects. The problem is kind of difficult to explain:
- my app has a plugin architecture, a la photoshop
- the image loading code is in a plugin (a dll)
- the dll loads an image file DcmFileFormat::loadFile()
- it then passes the DcmFileFormat object to a COM library (another dll)
- that dll copies the DcmFileFormat (because it needs to hang on to it)
Then all kinds of memory related problems occur when I try to manipulate the copied DcmFileFormat object. AFAICT, it seems that portions of the deep copy are not deep copied, thus resulting in heap errors. I tried the clone() method, and the copyFrom() method, and both exhibit the problem.
If I serialize the DcmFileFormat object between the two spaces, then all is good (which would seem to confirm my theory). The problem with that approach is that serialization is very slow (especially de-serialization).
I'm using a 3.6.1 July 27th 2012 snapshot.
How can I solve this issue? Does this ring a bell with anyone?
Thanks
Re: Problem with DcmFileFormat::clone()
Oh, if it's any help, the problem seems to be related to sequences.
For example, this will fail in the COM dll:
DcmFileFormat* copiedData = (DcmFileFormat*)sourceFF->clone();
DcmTagKey tag(24, 49);
const char* sValue = NULL;
OFCondition cond = copiedData->getDataset()->fingAndGetString(tag, sValue, OFTrue);
but this won't:
OFCondition cond = copiedData->getDataset()->fingAndGetString(tag, sValue, OFFalse);
For example, this will fail in the COM dll:
DcmFileFormat* copiedData = (DcmFileFormat*)sourceFF->clone();
DcmTagKey tag(24, 49);
const char* sValue = NULL;
OFCondition cond = copiedData->getDataset()->fingAndGetString(tag, sValue, OFTrue);
but this won't:
OFCondition cond = copiedData->getDataset()->fingAndGetString(tag, sValue, OFFalse);
-
- DCMTK Developer
- Posts: 2501
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
Re: Problem with DcmFileFormat::clone()
What happens if you print() the copied dataset/fileformat or if you save it to file? I mean when you compare the copied data structure with the "original" one.
Re: Problem with DcmFileFormat::clone()
Maybe I wasn't clear in my original posting, the problem is not with the results, the problems is that clone()ing a DcmFileFormat induces heap related memory errors as soon as I try manipulating sequences. And I mean cloning in two different "contexts", i.e. two different dlls.
If I transmit the DcmFileFormat through serialization, then I don't encounter those memory problems.
If I transmit the DcmFileFormat through serialization, then I don't encounter those memory problems.
-
- DCMTK Developer
- Posts: 2501
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
Re: Problem with DcmFileFormat::clone()
This is just a wild guess, but maybe the DcmTag references (inside the DcmObject instances) to the global data dictionary are the reason for your problems!? But then it should also occur when no sequences are contained in the dataset. I just checked the code, and the copy constructor of DcmTag looks ok to me ... at first glance.
Btw, there is no "3.6.1 July 27th 2012 snapshot" of DCMTK. Did you use the official shared library (DLL) support from DCMTK?
Btw, there is no "3.6.1 July 27th 2012 snapshot" of DCMTK. Did you use the official shared library (DLL) support from DCMTK?
Re: Problem with DcmFileFormat::clone()
Well the problem always occurs when deleting DcmStackNode instances (from the DcmStack destructor), so no it's not related to DcmTag instances.
The so-called snapshot I'm using was sent from someone at Offis (as it included the DcmPrint module). And no I'm not using shared dll mode, all my app is build using the static link mode (/MT) under Windows.
The so-called snapshot I'm using was sent from someone at Offis (as it included the DcmPrint module). And no I'm not using shared dll mode, all my app is build using the static link mode (/MT) under Windows.
Re: Problem with DcmFileFormat::clone()
Hi there
I've had pretty bad experiences in the past when linking with DLLs which have been solved by ensuring you use the same build settings for all the DLLs and EXEs, so I would strongly recommend looking at that (if you control all the DLLs !). Truth is, I can't remember the details now...
I've had pretty bad experiences in the past when linking with DLLs which have been solved by ensuring you use the same build settings for all the DLLs and EXEs, so I would strongly recommend looking at that (if you control all the DLLs !). Truth is, I can't remember the details now...
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest