[LITMUS^RT] A little confused on struct subtask subtasks[0]
Hang Su
hangsu.cs at gmail.com
Tue Feb 21 01:37:48 CET 2012
thanks. Glenn.
On Mon, Feb 20, 2012 at 4:46 PM, Glenn Elliott <gelliott at cs.unc.edu> wrote:
> Hi Hang Su,
>
> Zero-length arrays at the end of a struct is a trick that you'll see in C
> from time to time. Memory for the "struct pfair_param" instance is
> allocated dynamically with kmalloc. When this allocation is made, more
> than sizeof(struct pfair_param) memory is allocated. Thus, the subtasks
> array can be indexed past sizeof(struct pfair_param).
>
> In sched_pfair.c, find the line "param = kmallock(…)" Observe that extra
> memory is allocated with "quanta * sizeof(struct subtask)". This allocates
> space for the subtask array.
>
> Here's more information on this technique:
> http://stackoverflow.com/questions/295027/array-of-zero-length
>
> -Glenn
>
>
> On Feb 20, 2012, at 4:14 PM, Hang Su wrote:
>
> Hi all:
>
> I am reading source code about P-fair scheduling algorithm under
> /litmus/sched_pfair.c.* struct* subtask subtasks[0] is declared in *struct
> * pfair_param. From definition of function dump_subtasks(struct
> task_struct*t), subtasks is like a pointer to struct subtask or the name of
> a struct subtask array. But why it is declared as a struct subtask array
> with zero element ? is it as the same meaning as a pointer to struct
> subtask ?
>
>
> Thanks.
> _______________________________________________
> litmus-dev mailing list
> litmus-dev at lists.litmus-rt.org
> https://lists.litmus-rt.org/listinfo/litmus-dev
>
>
>
> _______________________________________________
> litmus-dev mailing list
> litmus-dev at lists.litmus-rt.org
> https://lists.litmus-rt.org/listinfo/litmus-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.litmus-rt.org/pipermail/litmus-dev/attachments/20120220/b4701379/attachment.html>
More information about the litmus-dev
mailing list