0

We have an array of structs like this one:

struct allocation
{
  size_t alloc_size_;

  char* alloc_memory_;
};

static struct allocation allocations[] =
  {{1024, NULL},{2048, NULL},};

later on in main() it's members alloc_memory_ are initialized using numa_alloc_onnode().

So the question: is alloc_memory_ also static and where they are located (heap, stack) ? If they are not static then how to make them static?

1 Answer 1

2

The alloc_memory_ member of array allocations are static, but the memory the pointed to are not necessarily static.

In your case, since you allocated them with numa_alloc_onnode in main, this means they pointed to dynamic storage.

If you really want static storage too, you can define the memory before the structure:

static char buffer1[1024];
static char buffer2[2048];

static struct allocation allocations[] = 
{ {1024, buffer1}, {2048, buffer2} };
Sign up to request clarification or add additional context in comments.

2 Comments

Ok thanks. In this case I would need a macro that would generate code type static char bufferN[SIZE];. Consider that static struct allocation allocations[] above is initialized as static struct allocation allocations[] = ALLOCATIONS;, where ALLOCATIONS is defined at compile time by user like -D'ALLOCATIONS={ {1024, buffer1}, {2048, buffer2} }' So the macro would have to parse { {1024, buffer1}, {2048, buffer2} } and generate code: static char buffer1[1024]; static char buffer2[2048];. Could you please point me to such a macro? Thanks
I suggest not passing code through macros, you could pass the size of the buffer though, static char buffer[N}; and -DN=1024

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.