LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

array content changes

I have lots of different char * xxxxx[1024] arrays defined and assigned in code.

I also use in some places of the code StrDup calls and free calls to manage memory.

At some point, few of earlier assigned char* arrays loose they values and become copies of data from other arrays and variables.

Obviously the code then gets out of control.

I suspect a memory leak, but don't know how to find it.

Don't have full dev. system, just basic CVI 2012.

I can step through the code and point to the place where array disruption happens by watching the arrays in var. watch window, but don't see any efficient way to prevent this from happening.

Any advice?

 

Thank you!

ALH
0 Kudos
Message 1 of 2
(2,588 Views)

Hi Alex_H

Without all of the toolkits from CVI 2012, the best approach would likely be to continue stepping through your code and make sure you are using good memory management practices. If you are doing any sort of synchronization or multithreading it may also be a potential race conditions. This particular issue is one of the challenges in C based programming when getting into memory and pointer use. What potentially could help is to deallocate and then null reference your pointers, and hopefully you can find a null reference exception to help find the point of failure.

 

I am not sure of your comfort and experience with C programming, but there are a decent number of good tutorials on good memory management that may be worth looking through and adopting where possible. Here are a few I found:

 

http://www.tutorialspoint.com/cprogramming/c_memory_management.htm

http://www.cprogramming.com/tutorial/c++_memory_problems.html (C++ but some principles will still apply)

http://www.codeproject.com/Articles/6920/Memory-Management-for-Beginners

 

That will likely be your best starting point as well as just working through your code or finding some sort of third party tools for more advanced debugging.

 

Regards,

James W.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 2
(2,569 Views)