When vectors are allocated, do they use memory on the heap or the stack?

Are all of the following statements true? vector<Type> vect; //allocates vect on stack and each of the Type (using std::allocator) also will be on the stack vector<Type> *vect = new vector<Type>; //allocates vect on heap and each of the Type will be allocated on stack vector<Type*> vect; //vect will be on stack and Type* will … Read more

How are multi-dimensional arrays formatted in memory?

In C, I know I can dynamically allocate a two-dimensional array on the heap using the following code: int** someNumbers = malloc(arrayRows*sizeof(int*)); for (i = 0; i < arrayRows; i++) { someNumbers[i] = malloc(arrayColumns*sizeof(int)); } Clearly, this actually creates a one-dimensional array of pointers to a bunch of separate one-dimensional arrays of integers, and “The … Read more

Stack vs heap allocation of structs in Go, and how they relate to garbage collection

I’m new to Go and I’m experiencing a bit of cognitive dissonance between C-style stack-based programming where automatic variables live on the stack and allocated memory lives on the heap and Python-style stack-based-programming where the only thing that lives on the stack are references/pointers to objects on the heap. As far as I can tell, … Read more

What are the dangers when creating a thread with a stack size of 50x the default?

I’m currently working on a very performance critical program and one path I decided to explore that may help reduce resource consumption was increasing my worker threads’ stack size so I can move most of the data (float[]s) that I’ll be accesing onto the stack (using stackalloc). I’ve read that the default stack size for … Read more