Originally posted by: TechBoyJK
the prefix of the array(global,local) just has to do with where it can be applied. Global is throughout the entire application, where as local would be for a certain function or object..... Am I on the right track?? This question was actually derived by my reading of a php tutorial, but I am really just looking for overall concepts, not just php, even though I do realize it changes somewhat from language to language.
Can anyone corrorobate this?Originally posted by: Elemental007
The specifics of global arrays are entirely dependant on the language. In PHP Iwouldn't worry about it.
But in C, you use global arrays because arrays passed as parameters to functions can severely impact the stack size and utlimtely overflow the main system stack, which is 1 MB for each thread. This is especially true with large arrays or arrays in recursive functions.
Originally posted by: manly
Can anyone corrorobate this?Originally posted by: Elemental007
The specifics of global arrays are entirely dependant on the language. In PHP Iwouldn't worry about it.
But in C, you use global arrays because arrays passed as parameters to functions can severely impact the stack size and utlimtely overflow the main system stack, which is 1 MB for each thread. This is especially true with large arrays or arrays in recursive functions.
I thought arrays are (basically) passed as a pointer in C.
That's also what I thought, and I was expecting you specifically to refute his statements.Originally posted by: Ameesh
Originally posted by: manly
Can anyone corrorobate this?Originally posted by: Elemental007
The specifics of global arrays are entirely dependant on the language. In PHP Iwouldn't worry about it.
But in C, you use global arrays because arrays passed as parameters to functions can severely impact the stack size and utlimtely overflow the main system stack, which is 1 MB for each thread. This is especially true with large arrays or arrays in recursive functions.
I thought arrays are (basically) passed as a pointer in C.
when passing arrays in C you always pass a pointer to the first element in the array, a good convention is also pass the size of the array with it. As far as I know its impossible to pass an array directly by value, they always go by reference.
you could do:
struct foo
{
int foo[100];
}
and then pass a foo into a function to pass an array by value but that is an asshole thing to do. i believ Elemental is talking out his ass.
Originally posted by: manly
That's also what I thought, and I was expecting you specifically to refute his statements.Originally posted by: Ameesh
Originally posted by: manly
Can anyone corrorobate this?Originally posted by: Elemental007
The specifics of global arrays are entirely dependant on the language. In PHP Iwouldn't worry about it.
But in C, you use global arrays because arrays passed as parameters to functions can severely impact the stack size and utlimtely overflow the main system stack, which is 1 MB for each thread. This is especially true with large arrays or arrays in recursive functions.
I thought arrays are (basically) passed as a pointer in C.
when passing arrays in C you always pass a pointer to the first element in the array, a good convention is also pass the size of the array with it. As far as I know its impossible to pass an array directly by value, they always go by reference.
you could do:
struct foo
{
int foo[100];
}
and then pass a foo into a function to pass an array by value but that is an asshole thing to do. i believ Elemental is talking out his ass.
and I was expecting you specifically to refute his statements
Exactly what it says: I know you're an experienced C programmer and would be able to definitively comment.Originally posted by: Ameesh
Originally posted by: manly
and I was expecting you specifically to refute his statements
what does that mean?
Actually no, arrays are passed as a copy of the pointer that points to the start of the array for call by value, and the actual array pointer itself if using call by reference.But in C, you use global arrays because arrays passed as parameters to functions can severely impact the stack size and utlimtely overflow the main system stack, which is 1 MB for each thread. This is especially true with large arrays or arrays in recursive functions.
Originally posted by: manly
Exactly what it says: I know you're an experienced C programmer and would be able to definitively comment.Originally posted by: Ameesh
Originally posted by: manly
and I was expecting you specifically to refute his statements
what does that mean?
Originally posted by: manly
That's also what I thought, and I was expecting you specifically to refute his statements.Originally posted by: Ameesh
Originally posted by: manly
Can anyone corrorobate this?Originally posted by: Elemental007
The specifics of global arrays are entirely dependant on the language. In PHP Iwouldn't worry about it.
But in C, you use global arrays because arrays passed as parameters to functions can severely impact the stack size and utlimtely overflow the main system stack, which is 1 MB for each thread. This is especially true with large arrays or arrays in recursive functions.
I thought arrays are (basically) passed as a pointer in C.
when passing arrays in C you always pass a pointer to the first element in the array, a good convention is also pass the size of the array with it. As far as I know its impossible to pass an array directly by value, they always go by reference.
you could do:
struct foo
{
int foo[100];
}
and then pass a foo into a function to pass an array by value but that is an asshole thing to do. i believ Elemental is talking out his ass.
Originally posted by: Elemental007
Originally posted by: manly
That's also what I thought, and I was expecting you specifically to refute his statements.Originally posted by: Ameesh
Originally posted by: manly
Can anyone corrorobate this?Originally posted by: Elemental007
The specifics of global arrays are entirely dependant on the language. In PHP Iwouldn't worry about it.
But in C, you use global arrays because arrays passed as parameters to functions can severely impact the stack size and utlimtely overflow the main system stack, which is 1 MB for each thread. This is especially true with large arrays or arrays in recursive functions.
I thought arrays are (basically) passed as a pointer in C.
when passing arrays in C you always pass a pointer to the first element in the array, a good convention is also pass the size of the array with it. As far as I know its impossible to pass an array directly by value, they always go by reference.
you could do:
struct foo
{
int foo[100];
}
and then pass a foo into a function to pass an array by value but that is an asshole thing to do. i believ Elemental is talking out his ass.
You might want to actually learn how C works you start accusing me of talking me out of my ass. The problem with most of these damn C courses is you never actually understand how the compiler works, other than you hit a little 'play' button and some stuff happens and a console pops up.
When you dynamically malloc() a variable, it goes onto a system heap. The only heap implementation that I've studied in detail is a Knuth heap which is more of an idealistic representation of a heap than anything else. When you allocate a global variable, it goes into a seperate block of memory that has been allocated by the system for all global variables. When you allocate a local variable (AKA A NON-GLOBAL VARIABLE) it goes onto the system stack. The variables are moved in LIFO order and the maximum stack size of each process is 1 MB.
Now, imagine that you locally define a variable of 10,000 double-precision numbers. Assuming its 32-bits per the IEEE floating point spec, its 8 bytes x 10,000 elements = 80,000 bytes for the array. So roughly slightly less than .1 MB of memory.
Those variables go onto the stack. Now, if you are using that function to call itself, it will push another copy of that function onto the stack, and reallocate another .08 MB array. Since most recursive functions are called thousands of times, you can see how you can crash the stack, right?
Now, if you were being smart and globally allocated that array, it would have been in seperate block of memory not tied to the stack.
Now, don't believe me? Fire up your compiler and define a series of global variables, then create main and call some other function and define the variables in there. Then malloc() another variable and print the addresses of each.
I await your apology.
Originally posted by: Elemental007
Originally posted by: manly
That's also what I thought, and I was expecting you specifically to refute his statements.Originally posted by: Ameesh
Originally posted by: manly
Can anyone corrorobate this?Originally posted by: Elemental007
The specifics of global arrays are entirely dependant on the language. In PHP Iwouldn't worry about it.
But in C, you use global arrays because arrays passed as parameters to functions can severely impact the stack size and utlimtely overflow the main system stack, which is 1 MB for each thread. This is especially true with large arrays or arrays in recursive functions.
I thought arrays are (basically) passed as a pointer in C.
when passing arrays in C you always pass a pointer to the first element in the array, a good convention is also pass the size of the array with it. As far as I know its impossible to pass an array directly by value, they always go by reference.
you could do:
struct foo
{
int foo[100];
}
and then pass a foo into a function to pass an array by value but that is an asshole thing to do. i believ Elemental is talking out his ass.
You might want to actually learn how C works you start accusing me of talking me out of my ass. The problem with most of these damn C courses is you never actually understand how the compiler works, other than you hit a little 'play' button and some stuff happens and a console pops up.
When you dynamically malloc() a variable, it goes onto a system heap. The only heap implementation that I've studied in detail is a Knuth heap which is more of an idealistic representation of a heap than anything else. When you allocate a global variable, it goes into a seperate block of memory that has been allocated by the system for all global variables. When you allocate a local variable (AKA A NON-GLOBAL VARIABLE) it goes onto the system stack. The variables are moved in LIFO order and the maximum stack size of each process is 1 MB.
Now, imagine that you locally define a variable of 10,000 double-precision numbers. Assuming its 32-bits per the IEEE floating point spec, its 8 bytes x 10,000 elements = 80,000 bytes for the array. So roughly slightly less than .1 MB of memory.
Those variables go onto the stack. Now, if you are using that function to call itself, it will push another copy of that function onto the stack, and reallocate another .08 MB array. Since most recursive functions are called thousands of times, you can see how you can crash the stack, right?
Now, if you were being smart and globally allocated that array, it would have been in seperate block of memory not tied to the stack.
Now, don't believe me? Fire up your compiler and define a series of global variables, then create main and call some other function and define the variables in there. Then malloc() another variable and print the addresses of each.
I await your apology.
That's nice but it has absolutely nothing to do with the issue at hand since no-one is using malloc(), new or any other derivatives of such. In fact your example uses dynamic memory allocation into the application's heap space while passing parameters (which is what we're discussing) only uses the stack.When you dynamically malloc() a variable, it goes onto a system heap.
Now THAT'S a good one!the maximum stack size of each process is 1 MB.
If i rember right its in a place called .BSS but i forgot what that stood for.