malloc, __nogc new , _CrtCheckMemory in managed c++

  • Thread starter Jochen Kalmbach [MVP]
  • Start date
J

Jochen Kalmbach [MVP]

Hi roni!
i have bug in my application that using managed c++ and unmanged dll (also
vb.net involved).
my question is about malloc , can i use malloc in the unmanaged part ?

You can it use *only* for unmanaged stuff.
i just want to know if malloc can cause some bug.

Normally not.
can i replace

malloc(1000); with _nogc new char[1000]; // i get the same size of
memory allocation ?

In this special case: Yes
In other cases where you do not allocate "char", you have to calculate
the size.
one more thing about catching bug when unmanaged memory allocation involved,
i saw somthing about using _CrtSetDbgFlag() _CrtCheckMemory() ,
this functions can help me find bug about data corruption in
unmanaged\managed app ?

This option is only for all allocations, which was done via the CRT; and
therefor it can only catch unmanaged allocations.
if yes, maybe someone have links to read how to use this functions.

See: _CrtSetDbgFlag
http://msdn.microsoft.com/library/en-us/vclib/html/_CRT__CrtSetDbgFlag.asp

See: _CrtCheckMemory
http://msdn.microsoft.com/library/en-us/vclib/html/_crt__crtcheckmemory.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
R

roni

hi.
i have bug in my application that using managed c++ and unmanged dll (also
vb.net involved).


my question is about malloc , can i use malloc in the unmanaged part ?

i just want to know if malloc can cause some bug.

now ,also im going to replace all the malloc with __nogc new .

can i replace

malloc(1000); with _nogc new char[1000]; // i get the same size of
memory allocation ?
----------------------
one more thing about catching bug when unmanaged memory allocation involved,
i saw somthing about using _CrtSetDbgFlag() _CrtCheckMemory() ,
this functions can help me find bug about data corruption in
unmanaged\managed app ?

if yes, maybe someone have links to read how to use this functions.


thanks,have a nice day.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top