|
i m using New and Delete in calling application(MFC).
but "delete []cData;" line have error runtime.
if we use cData='\0' and after this "delete []cData;"
then memory leak still continue.
|
|
|
|
|
shivanandgupta wrote: if we use cData='\0' and after this "delete []cData;"
then memory leak still continue.
That should not be a surprise...
Either you are just making a silly mistake (which we all do), or it's a bit more complex and you are allocating and freeing from different heaps. This could happen if you statically link to the C++ runtime.
One simple choice would be to use IMalloc to allocate / free chunks of memory. Look at CoGetMalloc etc for documentation.
I still think it's likely to be something dumb... Are you sure the memory is not already freed elsewhere?
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
Thanks for Reply
i am calling DLL statically
|
|
|
|
|
i don't have any idea to use Imalloc and cogetmalloc function to free memory.
i m using statically DLL not a COM
|
|
|
|
|
shivanandgupta wrote: if we use cData='\0' and after this "delete []cData;"
then memory leak still continue.
Well, if you set cData to '\0' you are manipulating the pointer, not the data it contains.
cData is set to null, and that is what you try to delete (and it always succeeds.)
Doesn't the DLL supply an API for freeing this string? IMHO dll's should always be designed that way.
|
|
|
|
|
if we use delete without using '\0' then problem occur about heap at run time.
|
|
|
|
|
Well, setting it to '\0' is the same as setting it to NULL. In either case, it makes the delete call a no-op, and that's why you don't get a crash, but you DO get a memory leak.
|
|
|
|
|
If the DLL allocates the memory using new , it should also be the one to delete[] it. So, let the DLL export a new function to free memory.
In your MFC program, you'd call the original method to allocate the char*, and afterwards you'd pass this pointer to the freeing function of the DLL, which would just delete[] it.
|
|
|
|
|
If the application is being build with the runtime libary (CRT) as a DLL (Recommended by Microsoft), then it should be possible to delete memory in the application that have been allocated by the DLL.
|
|
|
|
|
Correct. Based on the original question and replies, it was my impression that different heaps/CRTs are being used (see static linkage post), that's why I suggested this way. Of course, using only one CRT will solve the problem, too.
|
|
|
|
|
I m unable to use CRT
can u give some kind of code
|
|
|
|
|
Just follow what Dominik Reichl said in the first comment about ensuring that memory allocated in the DLL is released by the DLL again. Return the char-pointer to the DLL and let the DLL release it again.
|
|
|
|
|
return data char* is locally defined in DLL.
so how can release memory of that variable after returning
char* variable
|
|
|
|
|
When returning the char* then you take a copy of the char*, but they both point to the same memory in the heap of the DLL.
Just pass the copy of the char* from the application to the DLL again, and let the DLL release the memory in its heap.
You might consider returning a CString instead of a char*, and ensure that when the CString moves from DLL boundary to the Application boundary that a copy is made of the CString.
|
|
|
|
|
I have try but it is not working.
return char* is defined in dll's function as a local variable.
it will work well when we defined static variable. but i don't want
to create static variable in my DLL.
|
|
|
|
|
Thank you for confirming this. I'm in a situation myself where I'm considering to convert static-libraries into DLL's to improve linker times. The entire application is already using runtime library as DLL, so the conversion should be a matter of exporting all needed classes in the static libraries.
|
|
|
|
|
Hi...
i am creating a application in win32. i need to access the sql or MSAccess databse. but i don't know how to connect win32 application with sql or MSAccess database. please can any one help me?
thanking you
G.Paulraj
|
|
|
|
|
Are you using MFC? If so, then the MFC database connectivity classes[^] will be useful.
If you're not using MFC, then the ATL database classes[^] may be useful.
Other alternative technologies are ODBC[^], ADO[^] or DAO[^]. They'll all be painful (to some degree) to use with raw C++.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
How about reading about these api's from MSDN SQLHandle,SQLAllocHandle, SQLSetEnvAttr, SQLAllocHandle, SQLConnect, SQLAllocHandle, SQLExecDirec.
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
_AnsHUMAN_ wrote: SQLHandle, SQLAllocHandle, SQLSetEnvAttr, SQLAllocHandle, SQLConnect, SQLAllocHandle, SQLExecDirec.
Apparently, you want him to read-up about SQLAllocHandle() thrice?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
It's a very important function
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Makes perfect sense.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
|
hi i need the vc++ code that as to read chm file format.
thanks in advance
|
|
|
|
|
I hope the HTML Help SDK[^] may be of help to you.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|