Now I am confused again. I know new returns a pointer to some object like a simple int or an array or a struct or class, whatever. But does it also create a dynamic array of pointers and at the same time set aside a block of n structs? Does new guarantee all the structs will be contiguous in memory? Okay that seems like a silly question. So thread[1] is thread + sizeof Thread and thread[2] is thread + sizeof Thread * 2 etc. My way would be thread[2] = thread + sizeof pointer * 2. Thread can be extremely large and allocating a complete block of maxThreads might more easily fail. Allocating one Thread at a time might be less likely to fail. If someone wants 128 Threads and they do not have enough memory then one at a time allocation can be stopped at a lesser number of threads and reported to the user. Am I finally getting a handle on things??? Let me say a little prayer before you answer.Mergi wrote: ↑Fri Mar 04, 2022 2:02 amYea, this seems correct. But i'd still suggest getting rid of the extra indirection ... why do you need it? It will only make deallocation and memory management harder later on.Mike Sherwin wrote: ↑Fri Mar 04, 2022 1:59 am I just came up with this before seeing your reply.This looks logically correct to me.Code: Select all
thread = new Thread*[maxThreads]; for (s32 i = 0; i < maxThreads; i++) { thread[i] = new Thread; } t = thread[0];
![]()
