Davidlohr Bueso | 1 Jul 2011 19:58
Picon

Re: initializing a struct

On Thu, 2011-06-30 at 15:48 +0530, Vadiraj wrote:
> Hey Guys,
>  I'm stuck with logical reason for initializing a struct variable. Please help..
>  Consider a struct defined this way..
>  struct foo
>  {
>      int a;
>      char *ptr;
>  };
>  in my function I declare a local variable of this struct.
>  void bar()
>  {
>        struct foo local_var[10];
>        ...
>        ...
>  }
>  do you suspect a initialization issue? do we need to initialize the
> local array local_var[10] ? What's the best practice?

This kind of initialization is done with memset(), so can use 0s to
avoid random data.
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Randi Botse | 13 Jul 2011 13:54
Picon

Problem with scatter/gather IO

Hi,

I will read/write file with readv() and writev(), I have problem to
use that since the struct iovec will be a variable-length array, if i
have code.

struct foo {
    unsigned char data[100];
    unsigned char another_data[28];
};
unsigned len;
....

/* calculate len */
/* use len as array's member size */
struct iovec iov[len];
printf("len is: %i\n", len);
readv(fd, iov, len);

I got: BAD ADDRESS, and if I remove the printf() then I will get
INVALID ARGUMENT. What the possible problem with that?

Thanks,
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Leon Romanovsky | 13 Jul 2011 14:16
Picon

Re: Problem with scatter/gather IO

On Wed, Jul 13, 2011 at 14:54, Randi Botse <nightdecoder <at> gmail.com> wrote:
>
> Hi,
>
> I will read/write file with readv() and writev(), I have problem to
> use that since the struct iovec will be a variable-length array, if i
> have code.
>
> struct foo {
>    unsigned char data[100];
>    unsigned char another_data[28];
> };
> unsigned len;
> ....
>
> /* calculate len */
> /* use len as array's member size */
> struct iovec iov[len];
> printf("len is: %i\n", len);
> readv(fd, iov, len);
>
> I got: BAD ADDRESS, and if I remove the printf() then I will get
> INVALID ARGUMENT. What the possible problem with that?
>
> Thanks,
> --

Did you try "man readv" ?
You didn't initialized iovec struct.
http://pubs.opengroup.org/onlinepubs/009695399/functions/readv.html
(Continue reading)

Randi Botse | 14 Jul 2011 08:33
Picon

Fwd: Problem with scatter/gather IO

Ahh,, you are right Leon, each iov member need to be initialized
first, my bad. Everything is OK now. I also use sysconf(_SC_IOV_MAX)
to determine maximum iovs count.

Thanks,

On Wed, Jul 13, 2011 at 7:16 PM, Leon Romanovsky <leon <at> leon.nu> wrote:
> On Wed, Jul 13, 2011 at 14:54, Randi Botse <nightdecoder <at> gmail.com> wrote:
>>
>> Hi,
>>
>> I will read/write file with readv() and writev(), I have problem to
>> use that since the struct iovec will be a variable-length array, if i
>> have code.
>>
>> struct foo {
>>    unsigned char data[100];
>>    unsigned char another_data[28];
>> };
>> unsigned len;
>> ....
>>
>> /* calculate len */
>> /* use len as array's member size */
>> struct iovec iov[len];
>> printf("len is: %i\n", len);
>> readv(fd, iov, len);
>>
>> I got: BAD ADDRESS, and if I remove the printf() then I will get
>> INVALID ARGUMENT. What the possible problem with that?
(Continue reading)

Vadiraj | 21 Jul 2011 06:41
Picon

time system call expensive?

Hi All,

I'm evaluating time consumed by method. I'm using time(NULL) system
call to capture time before and after the call to the function.
Just wanted to know if this has a considerable performance hit? For
all I believe time syscall is quite optimized and should not really be
matter of concern.

Please let me know if someone have evaluated time(NULL) system over head..

Assuming the method I'm evaluating is a frequently called method.

Thanks in advance.

Regards,
Vadi
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Michal Nazarewicz | 21 Jul 2011 13:20
Favicon
Gravatar

Re: time system call expensive?

On Thu, 21 Jul 2011 06:41:14 +0200, Vadiraj <vadiraj.cs <at> gmail.com> wrote:
> I'm evaluating time consumed by method. I'm using time(NULL) system
> call to capture time before and after the call to the function.
> Just wanted to know if this has a considerable performance hit? For
> all I believe time syscall is quite optimized and should not really be
> matter of concern.
>
> Please let me know if someone have evaluated time(NULL) system over  
> head..
>
> Assuming the method I'm evaluating is a frequently called method.

Why do you worry about it?  What do you need the time for?  If are
really using time(2) it means that the function you're calling run time
is counted in seconds.  If that's the case, two call to time(2) are
by all means negligible.

If you need in for benchmark, you would probably do something like:

start = time(NULL)
for (vary big number)
     call function you benchmark
end = time(NULL)

In either case, you should check gettimeofday(2).

--

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michal "mina86" Nazarewicz    (o o)
(Continue reading)

Akos Marton | 21 Jul 2011 13:46
Picon

Re: time system call expensive?

I advice you `man 3 clock`.
If you want to get much more precision the attached project can help you.
Does it help?

Regards,
mAkos

Michal Nazarewicz wrote:
> On Thu, 21 Jul 2011 06:41:14 +0200, Vadiraj <vadiraj.cs <at> gmail.com> wrote:
>> I'm evaluating time consumed by method. I'm using time(NULL) system
>> call to capture time before and after the call to the function.
>> Just wanted to know if this has a considerable performance hit? For
>> all I believe time syscall is quite optimized and should not really be
>> matter of concern.
>>
>> Please let me know if someone have evaluated time(NULL) system over head..
>>
>> Assuming the method I'm evaluating is a frequently called method.
> 
> Why do you worry about it?  What do you need the time for?  If are
> really using time(2) it means that the function you're calling run time
> is counted in seconds.  If that's the case, two call to time(2) are
> by all means negligible.
> 
> If you need in for benchmark, you would probably do something like:
> 
> start = time(NULL)
> for (vary big number)
>     call function you benchmark
> end = time(NULL)
(Continue reading)

Vadiraj | 22 Jul 2011 06:57
Picon

Re: time system call expensive?

Great!! thanks for the tar.

I'm not sure if we can time() sys call is quite expensive all time.

Simple code I tried

#include <stdio.h>
#include <time.h>

int main()
{
    int i,k = 0;
    time_t t,j;
    for(i =0 ; i < 100; i++)
    {
        usleep(100);
        //t = time(NULL);
        k++;
        //j = time(NULL);
    }
}

Time without the time() calls.

time ./time_performance

real	0m2.091s
user	0m0.000s
sys	0m0.001s

(Continue reading)

mong hoi | 22 Jul 2011 22:10
Picon
Favicon

CODE NO:AM-001

Good Day,

I am Mr. Mong Hoi, Director of Operations of the Hang Seng Bank Ltd.Hong Kong.I have an obscured business
proposal for 
you.

Please reach me promptly if interested.Email: hoimong111 <at> hotmail.com.hk

Kind Regards,
Mr.Mong Hoi.
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

ratheesh kannoth | 29 Jul 2011 08:01
Picon

c++ code - not getting compiled !!!!!!!!!

#include <iostream>

using namespace std;

int main()
{
    int i;

    cout << "Enter value of i " << endl;
    cin >> i;

    if (i < 5)
        goto Sri;

    int j = 6;
    cout << "j = " << j << endl;

    cout << "Outside Sri" << endl;
    return 0;

Sri:
    cout << "Inside Sri" << endl;
    return 0;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

(Continue reading)


Gmane