Re: pack in structure or not?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>You mean passing structures to functions rather then tons of single                                   
>arguments?

Yes.
                                                                                                      
>If you pass the structure through a pointer you have the lowest costs.                                
>One pointer value instead of lots of value arguments.                                                 

But let's look how it looks like:
struct foo_arg args = {
  .arg1 = arg1,
  .arg2 = arg2,
...
};
<--- we occupy stack space here

foo(&args);

void foo(struct foo_arg *args)
{
  args->arg1 <--- we used pointer so we it slower then just
  arg1

//often used argument
  arg2 = args->arg2<-- we occupy stack space twice
}

                                                                                                      
>But I don't think it increases the clarity if you pack up all function                                
>arguments that have more then 2 values.

lets `foo' looks like:
void foo(int par1, int par2, int par3, int par4, int par5);

if we call it like this
foo(a + b, (c + d) << e, ...);
it is rather complex understand what's going on, but
struct foo_args args = {
 .par1 = a + b,
 .par2 = (c + d) << e,
};
foo(&args);

this code looks more clear for me.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux