RE: Kernel stack size
RE: Kernel stack size
- Subject: RE: Kernel stack size
- From: "Carl Smith" <email@hidden>
- Date: Wed, 13 Apr 2005 09:35:41 -0400
- Thread-topic: Kernel stack size
Hey Thanks Nikita, I did not know about the M_ZERO flag.
I appreciate you taking the time to give us all that tip.
Carl
-----Original Message-----
From: darwin-kernel-bounces+csmith=email@hidden
[mailto:darwin-kernel-bounces+csmith=email@hidden]
On Behalf Of Nikita Danilov
Sent: Wednesday, April 13, 2005 8:59 AM
To: Carl Smith
Cc: email@hidden
Subject: Re: Kernel stack size
Carl Smith writes:
>
> OK let me try it another way.
>
> I have this structure declared as global:
> Struct Frame_Data
> {
> void *buff1;
> void *buff2;
> void *buff3;
> }
>
> Then I declare as a global:
>
> Int g_Array_Cnt = 0;
>
> struct Frame_Data my_data[50];
>
> So in my kernel's init routine I do:
>
> While(g_Array_Cnt < 50)
> {
> if((my_data[g_Array_Cnt].buff1 = _MALLOC(1600, M_TEMP,
> M_WAITOK)) != 0)
> {
> bzero(&my_data[g_Array_Cnt].buff1, 1600);
>
> if((my_data[g_Array_Cnt].buff2 = _MALLOC(1600, M_TEMP,
> M_WAITOK)) != 0)
> {
> bzero(&my_data[g_Array_Cnt].buff2, 1600);
>
> if((my_data[g_Array_Cnt].buff3 = _MALLOC(1600,
> M_TEMP, M_WAITOK)) != 0)
> {
> bzero(&my_data[g_Array_Cnt].buff3,
> 1600);
> }
> else
> // error handling
> }
> else
> // error handling
> }
> else
> // error handling
This (after correcting obvious error pointed to by others in this
thread) can be simplified to
enum {
FRAME_BUF_SIZE = 1600
};
my_data[g_Array_Cnt].buff1 = _MALLOC(FRAME_BUF_SIZE,
M_TEMP, M_WAITOK | M_ZERO);
my_data[g_Array_Cnt].buff2 = _MALLOC(FRAME_BUF_SIZE,
M_TEMP, M_WAITOK | M_ZERO);
my_data[g_Array_Cnt].buff3 = _MALLOC(FRAME_BUF_SIZE,
M_TEMP, M_WAITOK | M_ZERO);
M_ZERO automatically zeroes allocated space, and M_WAITOK is guaranteed
to return non-NULL (or at least a _lot_ of places in core XNU code
assumes it is.). Identical calls to _MALLOC can be further factored into
special frame_alloc_buf() function.
Nikita.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
ch.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden