From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with realloc function

Hello,

I am dynamically building an array of strings. I have defined a pointer to pointer of char (char** MyPointer). To build the array I'm using the realloc-function for both dimensions of the array. This all works well until I want to "delete" the array for a new sequence. For this, I posted the following command:
MyPointer = realloc (MyPointer, 0);
The pointer is set to NULL after this. Now, I want to build the array again and this does not work! I'm not able to allocate more than one char* for the char** MyPointer. I also tried to free the char**, then use malloc and realloc, this doesn't work as well.
I have attached the functions that I'm using to build, rebuild and delete the array.
0 Kudos
Message 1 of 5
(2,956 Views)
Hi,

I would like to post you a link to a KB, which explains the dynamically allocation of arrays.
http://digital.ni.com/public.nsf/websearch/119E4AA17E0A6F9C86256C4E00568121?OpenDocument

Please let me know if you still have problems.

Evrem Yarkin
Application Engineer
0 Kudos
Message 2 of 5
(2,956 Views)
Hello,

Please read my request and my example.c File again, it's not the problem that I don't know how to allocate memory dynamicly. I found out, that perhaps the variables windows has a bug. When dynamicly allocating memory to a variable and writing content into it, the variables-window is not always updated.
So I can't trust what I see in the variables windows, cause it's not in each case the same that is effectivly stored in memory.
0 Kudos
Message 3 of 5
(2,956 Views)
Hi,

I posted the link because normally we do not have any problems with that. Please provide a simple source code file, which i can run without having to declare a lot of variables and describe on which line the variable window misbehaves and what your expectations are.

Evrem Yarkin
0 Kudos
Message 4 of 5
(2,956 Views)
Hello,

I now made a simple code file which you can debug. Watch the variable "StepLBDetail" in the variables window. Please open up the StepLBDetail** variable after the first command (Line11) . You can see a char* with the text "Hello world". After the second command the Variables window is not updated before you close and open the StepLBDetail** variable again.
After the "StepLBDelete" command the Variables window only shows one char* after several times adding text with the "StepLBAdd" Command. It is no more updated.
0 Kudos
Message 5 of 5
(2,956 Views)