I convert a lot of text with mdlText_getElementDescr:
status=mdlText_getElementDescr (&edPText, &edP->el.text_2d, NULL);
if (status == SUCCESS)
{
// do nothing mdlElmdscr_freeAll(&edPText);
}
Used Memory grows over the time. Is there really a bug in this function? How to free the Memory? Is there any Workaround?
Unknown said:mdlText_getElementDescr (&edPText, &edP->el.text_2d, NULL)
I see that you frree edPText, but what about edP? If edP is a text element, why not use that descriptor?
Regards, Jon Summers LA Solutions
Unknown said:of course edP is freed
Where does edP originate? If it's from a model scan, then you should not free it.
Unknown said:It is from model scan.But why it should not freed?
Whether it should or should not be freed depends on how you write your scan. If you explicitly read the element descriptor in your scan code, then the descriptor is yours to free. If, on the other hand, you use an element descriptor provided by a scan callback function, then the descriptor is not yours to free.
Example (from MDL help) of reading an element descriptor yourself:
do { scanSize = sizeof (scanBuf) / sizeof (short); scanStatus = mdlScanCriteria_scan (oscP,scanBuf,&scanSize,&scanPosition); for (lP = scanBuf; lP < scanBuf + scanSize / 2; ++lP) { MSElementDescr *edP; if (mdlElmdscr_readToMaster (&edP, *lP, mdlModelRef_getActive(), FALSE, NULL)) { ... mdlElmdscr_freeAll (&edP); } } } while (scanStatus == BUFF_FULL);
Example of scan callback:
// In your scan function mdlScanCriteria_setElmDscrCallback (pScanCrit, (PFScanElemDscrCallback)writeWorkFunc, (void*)cpArgms); mdlScanCriteria_scan (pScanCrit, NULL, NULL,NULL);
The scan callback function:
int writeWorkFunc ( MSElementDescr* edP, /* => This descriptor is not yours (should be MSElementDescr const* edP) */ void* args, ScanCriteria* scP ) { MSElementDescr *newDescrP = NULL; /* Here's how to obtain a descriptor that belongs to you */ mdlElmdscr_duplicate (&newDescrP,edP); /* Do something with duplicate descriptor */ mdlElmdscr_freeAll (&newDescrP); /* But don't free edP */ return SUCCESS; }
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Tom,
Unknown said:here is the code
Thanks! Right now I have no idea what is wrong, but let's hope somebody else will have an idea.
Can you please edit your post and to use Syntaxhighlighter (yellow pencil icon in Advanced Editor mode) and set the language to C++, so you code will be displayed not as ugly plain text but as the real code?
Unknown said:The effect is only with true type text.
This is weird.
But some information still missing:
Unknown said:I started with mdl over 20 years ago
I understand, but it's not good. In such case I would still use assembler for 8bit processors and Pascal ;-)
Unknown said:...and it runs
Will not anymore pretty soon. MicroStation CONNECT Edition doesn't support pseudocode applications, so you will have to migrate your code to native MDL anyway and it's for sure better to migrate pseudocode app to native code at first in MicroStation V8i and in the next step to migrate working native code to CONNECT Edition than to try to solve both tasks at the same time ... in such case maybe it's easier to write the application from scratch.
And even in V8i it's not only recommended, but also better to use native C/C++ code, because of more standard programming environment and also an access to new MicroStationAPI that provides some extra features compring to C MDL API.
With regards,
Jan