This is a two part post so bear with me.
Question Part 1, char* memory management
I generally work with C++ and so avoid C strings as a rule but I'm working with a library developed in C which requires POD's to function properly so I'm forced to work with char* arrays (all of the access functions are wrapped inside C++ class interface functions so I can at least keep it all in one neat and tidy package).
I'm not doing anything advanced with said string (e.g., no strcmp()'s, strcat()'s, strlen()'s, etc.) so I'm really only worried about properly initializing, freeing, resizing, etc. With the below code (assuming that the actions filling the array with data knows the correct size inclusive of a trailing null terminator byte), is it correct in terms of properly managing the memory allocated?
Code:
char *myString = new char[someSize];
/* Perform some sort of action that fills the array with meaningful data. */
free(myString);
myString = new char[someOtherSize];
/* Repeat process. */
Question Part 2, Threading
Hope this is the appropriate forum so if it's not point me in the right direction and I'll edit this post and move this part of the question to a more appropriate thread.
I'm very very new to multithreading. I generally understand how threading works on low level but I don't know how to effectively apply it within my own application. I'm using SDL's functions for creating and managing threads and mutex's to keep things simple and cross-platform.
Various states are set before the thread starts and are dependant on when the thread completes. While the thread is executing, it will be accessing two variables, the above c-string which will only be accessed within the function executing in a separate thread and a float value that's accessed by both threaded function the parent thread simultaneously.
Creating a thread is straight-forward. Passing in the data that I need to access is also straight-forward. My question is primarily about when and where I should use a mutex to properly lock a particular resource, if at all, and which resources need to be locked.
Thanks for your time!