Array Allocation

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Lprogster
Member
Member
Posts: 174
Joined: Tue Nov 14, 2006 11:59 am

Array Allocation

Post by Lprogster »

Hey everyone :)

...

Thank you,
Lster
Last edited by Lprogster on Tue Oct 23, 2007 11:22 am, edited 1 time in total.
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

Post by mathematician »

Quite possibly I am misunderstanding, but wouldn't you necessarily get a page fault if you tried to write to an area of memory without first making an entry in a page table (saying that the relevant page is present)?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

where are you defining that array? If you do that on the stack (i.e. inside a function) you can run out of stack space and suffer the consequences
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Lprogster
Member
Member
Posts: 174
Joined: Tue Nov 14, 2006 11:59 am

Post by Lprogster »

...

Thanks,
Lster
Last edited by Lprogster on Tue Oct 23, 2007 11:22 am, edited 1 time in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

gcc will put the array on the stack, somewhere within the functions stack frame. The address itself is simple to get:

unsigned int address = (unsigned int) &(array[0]);

nevertheless, its bad practice to create large arrays on the stack in kernel code. Even a set of small arrays can quickly overflow the stack. Using things other than (unsigned) char will only make matters worse by several factors. Unless you know for sure the array will always fit within the stack, do not allocate it there.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply