Using static for a Large Data Structure
-
I have a large data array and was told to make it static to ensure that I have enough storage allocated
DATA_DETAILS signal_details[NO_FIELDS] = { "1.000000", // Scaling "Integer", // Display Format "0", // Raw Data String "0", // Engineering Data String etc
Note NO_FIELDS could be 25,000 and some of the elements are char arrays of 4096 bytes. i.e. lots of data. Now if I make it static; e.g.static DATA_DETAILS signal_details[NO_FIELDS] = { "1.000000", // Scaling "Integer", // Display Format "0", // Raw Data String "0", // Engineering Data String etc
the project fails to build as I have extern references; e.g including the keyword static causes a problem.extern static DATA_DETAILS signal_details[NO_FIELDS];
How can I overcome this problem please. -
I have a large data array and was told to make it static to ensure that I have enough storage allocated
DATA_DETAILS signal_details[NO_FIELDS] = { "1.000000", // Scaling "Integer", // Display Format "0", // Raw Data String "0", // Engineering Data String etc
Note NO_FIELDS could be 25,000 and some of the elements are char arrays of 4096 bytes. i.e. lots of data. Now if I make it static; e.g.static DATA_DETAILS signal_details[NO_FIELDS] = { "1.000000", // Scaling "Integer", // Display Format "0", // Raw Data String "0", // Engineering Data String etc
the project fails to build as I have extern references; e.g including the keyword static causes a problem.extern static DATA_DETAILS signal_details[NO_FIELDS];
How can I overcome this problem please. -
I have a large data array and was told to make it static to ensure that I have enough storage allocated
DATA_DETAILS signal_details[NO_FIELDS] = { "1.000000", // Scaling "Integer", // Display Format "0", // Raw Data String "0", // Engineering Data String etc
Note NO_FIELDS could be 25,000 and some of the elements are char arrays of 4096 bytes. i.e. lots of data. Now if I make it static; e.g.static DATA_DETAILS signal_details[NO_FIELDS] = { "1.000000", // Scaling "Integer", // Display Format "0", // Raw Data String "0", // Engineering Data String etc
the project fails to build as I have extern references; e.g including the keyword static causes a problem.extern static DATA_DETAILS signal_details[NO_FIELDS];
How can I overcome this problem please. -
I have a large data array and was told to make it static to ensure that I have enough storage allocated
DATA_DETAILS signal_details[NO_FIELDS] = { "1.000000", // Scaling "Integer", // Display Format "0", // Raw Data String "0", // Engineering Data String etc
Note NO_FIELDS could be 25,000 and some of the elements are char arrays of 4096 bytes. i.e. lots of data. Now if I make it static; e.g.static DATA_DETAILS signal_details[NO_FIELDS] = { "1.000000", // Scaling "Integer", // Display Format "0", // Raw Data String "0", // Engineering Data String etc
the project fails to build as I have extern references; e.g including the keyword static causes a problem.extern static DATA_DETAILS signal_details[NO_FIELDS];
How can I overcome this problem please.When you were told to make it static, they probably meant it in the context of where you allocate it ( stack or heap ). If you use operator new with such a large struct there is a good change you will run out of memory, but declaring it on the stack, as it appears in your code, you are guaranteed to have the memory before you run your exe.
-
When you were told to make it static, they probably meant it in the context of where you allocate it ( stack or heap ). If you use operator new with such a large struct there is a good change you will run out of memory, but declaring it on the stack, as it appears in your code, you are guaranteed to have the memory before you run your exe.
WalderMort wrote:
you are guaranteed to have the memory before you run your exe
It depends upon how big is your stack...:):-D:) Anyway, as far as I know, you don't need to declare
static
a local variable to have guaranteed memory for it.... -- modified at 9:40 Thursday 23rd November, 2006 -
WalderMort wrote:
you are guaranteed to have the memory before you run your exe
It depends upon how big is your stack...:):-D:) Anyway, as far as I know, you don't need to declare
static
a local variable to have guaranteed memory for it.... -- modified at 9:40 Thursday 23rd November, 2006static vars are not stored in the stack so in a way if you declare a var static, the memory is guaranteed for that var.
-Prakash
-
static vars are not stored in the stack so in a way if you declare a var static, the memory is guaranteed for that var.
-Prakash
-
static vars are not stored in the stack so in a way if you declare a var static, the memory is guaranteed for that var.
-Prakash
well static and extern do not o hand in hand. but what abt the case when we have to make this structure visible to other files(declare extern) and also have guaranteed memory allocation assumin the structure is not local to any function. Is it that the allocatin shall be made on the stack for a function using it.
-
well static and extern do not o hand in hand. but what abt the case when we have to make this structure visible to other files(declare extern) and also have guaranteed memory allocation assumin the structure is not local to any function. Is it that the allocatin shall be made on the stack for a function using it.
tom groezer wrote:
Is it that the allocatin shall be made on the stack for a function using it.
Since the structure is declared in someother file, and used as extern in other files or function, the memory is still allocated to the structure, if the function is making a copy of the structure into its stack then its a different thing, but the original structure has been memory preallocated.
-Prakash