Er...this may be a major point I'm missing, but if my arrays are dying when the function ends, wouldn't a casted malloc-ed memory block go out of scope as well?
Actually, I guess not, since the actual pointer data is casted and then assigned to the Model structure, which wouldn't go out of scope...right? In my code, the pointers to the temp_arrays don't go out of scope (because they're part of the model structure), but the actual data and memory structure do, right? Something like that? And that's why I would need to do a malloc and cast in a single assignment to "model", to preserve that memory, right?
Thanks for the response though. I didn't even think of that...I figured if I just saved the pointers, the arrays wouldn't go out of scope, but I guess I was wrong...still new to C 🙂
Actually, I guess not, since the actual pointer data is casted and then assigned to the Model structure, which wouldn't go out of scope...right? In my code, the pointers to the temp_arrays don't go out of scope (because they're part of the model structure), but the actual data and memory structure do, right? Something like that? And that's why I would need to do a malloc and cast in a single assignment to "model", to preserve that memory, right?
Thanks for the response though. I didn't even think of that...I figured if I just saved the pointers, the arrays wouldn't go out of scope, but I guess I was wrong...still new to C 🙂