Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force GCC to forgo zeroing certain globals

Tags:

c

gcc

Is there any way to tell GCC to not initialize a particular global array to zero?

I want to reserve a large chunk of memory for storing a large data structure that my code manages, so I say:

#define SIZE_16_MB 0x01000000
BYTE mChunkSpace[SIZE_16_MB];

The problem is that crtinit() takes a million years to initialize this space to zero, and it is not at all necessary.

Is there any way I can force it not to initialize that space?

Currently I am hard-coding a memory address that is outside what the linker knows about, but that is not a particularly robust way of doing things.

Additionally, this is a slow embedded proc (50MHz Microblaze), so don't assume that i am talking about a PC. It really does take a long time to zero that space.

like image 213
NXT Avatar asked Jun 24 '12 20:06

NXT


1 Answers

You can use the gcc attributes to store the object in another new memory section, like for example in the .noinit memory section.

 BYTE mChunkSpace[SIZE_16_MB] __attribute__ ((section (".noinit")));
like image 88
ouah Avatar answered Oct 19 '22 23:10

ouah