Speed of finding a size of an array.

Discussion in 'C Programming' started by Annajiat, Dec 9, 2005.

  1. Annajiat

    Annajiat Guest

    Hi,
    a)
    int grid[1010][1010];
    Which of the following is faster?
    1. memset(grid,0,1010*1010);
    2. memset(grid,0,sizeof(grid));

    b) Is there any faster alternative to initializing memory?

    c) What is the difference between comp.lang.c and alt.comp.lang.c ?

    d) Is there any performance difference in local and global array?

    Thanking you
    আনà§à¦¨à¦¾à¦¿à¦œà§Ÿà¦¾à¦¤ আলীম রােসল
    Annajiat Alim Rasel
    Secretary
    BUCC
    BRAC University Computer Club
    BUCC: http://groups-beta.google.com/group/bucc
    BUCC Programming Contest Wing:
    http://groups.yahoo.com/group/buacm
    http://groups-beta.google.com/group/buacm





    Monga Crisis:
    http://adnan.phpxperts.com/monga/
    http://adnan.phpxperts.com/monga/feedback.php

    Quote: I don't talk. I don't talk much. However, when I talk, I forget
    to stop.
     
    Annajiat, Dec 9, 2005
    #1
    1. Advertising

  2. Annajiat wrote:
    > Hi,
    > a)
    > int grid[1010][1010];
    > Which of the following is faster?
    > 1. memset(grid,0,1010*1010);
    > 2. memset(grid,0,sizeof(grid));


    1. since you initialize only part of the array (typically
    sizeof(int)/sizeof(char)) but this is probably not what you expected.

    > b) Is there any faster alternative to initializing memory?


    int *g = (int*)grid;
    int *p = g + 1010*1010;
    while(p-- != g)
    *p = 0;

    ?

    > c) What is the difference between comp.lang.c and alt.comp.lang.c ?


    alt.

    > d) Is there any performance difference in local and global array?


    should not.

    a+, ld.
     
    Laurent Deniau, Dec 9, 2005
    #2
    1. Advertising

  3. Annajiat

    pete Guest

    Annajiat wrote:
    >
    > Hi,
    > a)
    > int grid[1010][1010];
    > Which of the following is faster?
    > 1. memset(grid,0,1010*1010);
    > 2. memset(grid,0,sizeof(grid));


    1 would probably be faster.
    sizeof grid is equal to 1010*1010*sizeof(int),
    so 1 and 2 are different.
    Usually when people ask "which is faster?"
    they mean for two equivalent operations.

    --
    pete
     
    pete, Dec 9, 2005
    #3
  4. <> wrote:
    >int grid[1010][1010];
    >Which of the following is faster?
    >1. memset(grid,0,1010*1010);
    >2. memset(grid,0,sizeof(grid));


    You probably meant:
    1. memset(grid,0,1010*1010*sizeof(int));
    Otherwise the two statements are not equivalent.

    I would expect a modern compiler to compute
    the result of "1010*1010*sizeof(int)" at compile
    time, therefore there would be no difference
    between 1. & 2.
    If that is not the case, then the only difference
    would be the time required to compute the product.

    >b) Is there any faster alternative to initializing memory?

    That depends on the target CPU, the compiler being used and
    the details of the memset() provided in the C library you
    are using.

    >c) What is the difference between comp.lang.c and alt.comp.lang.c ?

    I have not looked into alt.comp.lang.c, so I do not know
    anything about its current contents, level, etc.
    In general, anybody can create a newsgroup under the "alt."
    hierarchy, creating a group under "comp." requires a formal
    proposal & voting process.

    >d) Is there any performance difference in local and global array?

    As in b) depends on CPU and compiler. You should run a test to
    find out in your system.

    Roberto Waltman

    [ Please reply to the group, ]
    [ return address is invalid. ]
     
    Roberto Waltman, Dec 9, 2005
    #4
  5. In article <>,
    Roberto Waltman <> wrote:

    > <> wrote:
    > >int grid[1010][1010];
    > >Which of the following is faster?
    > >1. memset(grid,0,1010*1010);
    > >2. memset(grid,0,sizeof(grid));

    >
    > You probably meant:
    > 1. memset(grid,0,1010*1010*sizeof(int));
    > Otherwise the two statements are not equivalent.
    >
    > I would expect a modern compiler to compute
    > the result of "1010*1010*sizeof(int)" at compile
    > time, therefore there would be no difference
    > between 1. & 2.


    You are overlooking a small, but important detail, which doesn't only
    affect execution speed, but also correctness.
     
    Christian Bau, Dec 9, 2005
    #5
  6. On Fri, 09 Dec 2005 18:11:14 +0000, Christian Bau wrote:

    > In article <>,
    > Roberto Waltman <> wrote:
    >
    >> <> wrote:
    >> >int grid[1010][1010];
    >> >Which of the following is faster?
    >> >1. memset(grid,0,1010*1010);
    >> >2. memset(grid,0,sizeof(grid));

    >>
    >> You probably meant:
    >> 1. memset(grid,0,1010*1010*sizeof(int));
    >> Otherwise the two statements are not equivalent.
    >>
    >> I would expect a modern compiler to compute
    >> the result of "1010*1010*sizeof(int)" at compile
    >> time, therefore there would be no difference
    >> between 1. & 2.

    >
    > You are overlooking a small, but important detail, which doesn't only
    > affect execution speed, but also correctness.


    Great... I love puzzles.

    memset sets byte and will *incorrectly* chop 0x3F2 to 0xF2. Subsequent
    inspection of the array will then yield 0xF2F2F2F2 as raw integer value
    which (probably) isn't what the OP expects (assuming a 32 bit integer).

    Right?
     
    Kleuskes & Moos, Dec 9, 2005
    #6
  7. Annajiat

    Ben Pfaff Guest

    Kleuskes & Moos <> writes:

    > On Fri, 09 Dec 2005 18:11:14 +0000, Christian Bau wrote:
    >
    >> In article <>,
    >> Roberto Waltman <> wrote:
    >>> 1. memset(grid,0,1010*1010*sizeof(int));

    >> You are overlooking a small, but important detail, which doesn't only
    >> affect execution speed, but also correctness.

    > Great... I love puzzles.
    >
    > memset sets byte and will *incorrectly* chop 0x3F2 to 0xF2. Subsequent
    > inspection of the array will then yield 0xF2F2F2F2 as raw integer value
    > which (probably) isn't what the OP expects (assuming a 32 bit integer).
    >
    > Right?


    No. Completely wrong.
    --
    A competent C programmer knows how to write C programs correctly,
    a C expert knows enough to argue with Dan Pop, and a C expert
    expert knows not to bother.
     
    Ben Pfaff, Dec 9, 2005
    #7
  8. <> wrote:
    Christian Bau wrote:
    >> Roberto Waltman <> wrote:
    >>> >int grid[1010][1010];
    >>> >Which of the following is faster?
    >>> >1. memset(grid,0,1010*1010);
    >>> >2. memset(grid,0,sizeof(grid));
    >>>
    >>> You probably meant:
    >>> 1. memset(grid,0,1010*1010*sizeof(int));
    >>> Otherwise the two statements are not equivalent.
    >>>
    >>> I would expect a modern compiler to compute
    >>> the result of "1010*1010*sizeof(int)" at compile
    >>> time, therefore there would be no difference
    >>> between 1. & 2.

    >>
    >> You are overlooking a small, but important detail, which doesn't only
    >> affect execution speed, but also correctness.

    >
    >Great... I love puzzles.
    >
    >memset sets byte and will *incorrectly* chop 0x3F2 to 0xF2. Subsequent
    >inspection of the array will then yield 0xF2F2F2F2 as raw integer value
    >which (probably) isn't what the OP expects (assuming a 32 bit integer).
    >
    >Right?


    Wrong. And no puzzle here. Christian refers to the
    fact that "memset(grid,0,sizeof(grid))" will always
    have the correct size of grid, while the correctness
    of the other statement depends on the programmer
    updating it manually if the size of grid changes.

    Roberto Waltman

    [ Please reply to the group, ]
    [ return address is invalid. ]
     
    Roberto Waltman, Dec 9, 2005
    #8
  9. Kleuskes & Moos <> writes:
    > On Fri, 09 Dec 2005 18:11:14 +0000, Christian Bau wrote:
    >> In article <>,
    >> Roberto Waltman <> wrote:
    >>
    >>> <> wrote:
    >>> >int grid[1010][1010];
    >>> >Which of the following is faster?
    >>> >1. memset(grid,0,1010*1010);
    >>> >2. memset(grid,0,sizeof(grid));
    >>>
    >>> You probably meant:
    >>> 1. memset(grid,0,1010*1010*sizeof(int));
    >>> Otherwise the two statements are not equivalent.
    >>>
    >>> I would expect a modern compiler to compute
    >>> the result of "1010*1010*sizeof(int)" at compile
    >>> time, therefore there would be no difference
    >>> between 1. & 2.

    >>
    >> You are overlooking a small, but important detail, which doesn't only
    >> affect execution speed, but also correctness.

    >
    > Great... I love puzzles.
    >
    > memset sets byte and will *incorrectly* chop 0x3F2 to 0xF2. Subsequent
    > inspection of the array will then yield 0xF2F2F2F2 as raw integer value
    > which (probably) isn't what the OP expects (assuming a 32 bit integer).


    Nope. 0x3F2 is 1010 decimal, and is used in the third argument to
    memset(), which is of type size_t. It's not truncated to a byte.

    You'll find the answer in other responses in this thread. If you want
    to figure it out for yourself, ask yourself why these two:
    memset(grid,0,1010*1010);
    memset(grid,0,sizeof(grid));
    are *not* equivalent.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Dec 9, 2005
    #9
  10. In article <>,
    Kleuskes & Moos <> wrote:

    > On Fri, 09 Dec 2005 18:11:14 +0000, Christian Bau wrote:
    >
    > > In article <>,
    > > Roberto Waltman <> wrote:
    > >
    > >> <> wrote:
    > >> >int grid[1010][1010];
    > >> >Which of the following is faster?
    > >> >1. memset(grid,0,1010*1010);
    > >> >2. memset(grid,0,sizeof(grid));
    > >>
    > >> You probably meant:
    > >> 1. memset(grid,0,1010*1010*sizeof(int));
    > >> Otherwise the two statements are not equivalent.
    > >>
    > >> I would expect a modern compiler to compute
    > >> the result of "1010*1010*sizeof(int)" at compile
    > >> time, therefore there would be no difference
    > >> between 1. & 2.

    > >
    > > You are overlooking a small, but important detail, which doesn't only
    > > affect execution speed, but also correctness.

    >
    > Great... I love puzzles.
    >
    > memset sets byte and will *incorrectly* chop 0x3F2 to 0xF2. Subsequent
    > inspection of the array will then yield 0xF2F2F2F2 as raw integer value
    > which (probably) isn't what the OP expects (assuming a 32 bit integer).


    The first one sets 1010 * 1010 bytes.
    The second one sets 1010 * 1010 ints. Which is usually two or four times
    more than 1010 bytes.
     
    Christian Bau, Dec 9, 2005
    #10
  11. In article <>,
    Roberto Waltman <> wrote:

    > <> wrote:
    > Christian Bau wrote:
    > >> Roberto Waltman <> wrote:
    > >>> >int grid[1010][1010];
    > >>> >Which of the following is faster?
    > >>> >1. memset(grid,0,1010*1010);
    > >>> >2. memset(grid,0,sizeof(grid));
    > >>>
    > >>> You probably meant:
    > >>> 1. memset(grid,0,1010*1010*sizeof(int));
    > >>> Otherwise the two statements are not equivalent.
    > >>>
    > >>> I would expect a modern compiler to compute
    > >>> the result of "1010*1010*sizeof(int)" at compile
    > >>> time, therefore there would be no difference
    > >>> between 1. & 2.
    > >>
    > >> You are overlooking a small, but important detail, which doesn't only
    > >> affect execution speed, but also correctness.

    > >
    > >Great... I love puzzles.
    > >
    > >memset sets byte and will *incorrectly* chop 0x3F2 to 0xF2. Subsequent
    > >inspection of the array will then yield 0xF2F2F2F2 as raw integer value
    > >which (probably) isn't what the OP expects (assuming a 32 bit integer).
    > >
    > >Right?

    >
    > Wrong. And no puzzle here. Christian refers to the
    > fact that "memset(grid,0,sizeof(grid))" will always
    > have the correct size of grid, while the correctness
    > of the other statement depends on the programmer
    > updating it manually if the size of grid changes.


    Just to make sure we are talking about the same things:

    > >>> >int grid[1010][1010];
    > >>> >Which of the following is faster?
    > >>> >1. memset(grid,0,1010*1010);
    > >>> >2. memset(grid,0,sizeof(grid));


    1. Contains an absolut blatant error that will make you wish you could
    disappear in the ground when you spot it. You are probably looking for
    some subtle mistake. There is nothing subtle about it.
     
    Christian Bau, Dec 9, 2005
    #11
  12. Christian Bau <> wrote:

    > > > Roberto Waltman <> wrote:


    > > >> You probably meant:
    > > >> 1. memset(grid,0,1010*1010*sizeof(int));
    > > >> Otherwise the two statements are not equivalent.


    > The first one sets 1010 * 1010 bytes.
    > The second one sets 1010 * 1010 ints. Which is usually two or four times
    > more than 1010 bytes.


    Unless I'm missing something, Roberto was aware of that difference and
    said so.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Dec 9, 2005
    #12
  13. In article <dncr9j$4jj$>,
    Christopher Benson-Manica <> wrote:

    > Christian Bau <> wrote:
    >
    > > > > Roberto Waltman <> wrote:

    >
    > > > >> You probably meant:
    > > > >> 1. memset(grid,0,1010*1010*sizeof(int));
    > > > >> Otherwise the two statements are not equivalent.

    >
    > > The first one sets 1010 * 1010 bytes.
    > > The second one sets 1010 * 1010 ints. Which is usually two or four times
    > > more than 1010 bytes.

    >
    > Unless I'm missing something, Roberto was aware of that difference and
    > said so.


    It seems I was completely thrown off by the second sentence of his reply

    > I would expect a modern compiler to compute
    > the result of "1010*1010*sizeof(int)" at compile
    > time, therefore there would be no difference
    > between 1. & 2.


    and somehow missed that _he_ was the one who posted the correction from

    > > > >> 1. memset(grid,0,1010*1010);


    to

    > > > >> 1. memset(grid,0,1010*1010*sizeof(int));


    Apologies. My fault.
     
    Christian Bau, Dec 9, 2005
    #13
  14. On Fri, 09 Dec 2005 10:45:48 -0800, Ben Pfaff wrote:

    > Kleuskes & Moos <> writes:
    >
    >> On Fri, 09 Dec 2005 18:11:14 +0000, Christian Bau wrote:
    >>
    >>> In article <>,
    >>> Roberto Waltman <> wrote:
    >>>> 1. memset(grid,0,1010*1010*sizeof(int));
    >>> You are overlooking a small, but important detail, which doesn't only
    >>> affect execution speed, but also correctness.

    >> Great... I love puzzles.
    >>
    >> memset sets byte and will *incorrectly* chop 0x3F2 to 0xF2. Subsequent
    >> inspection of the array will then yield 0xF2F2F2F2 as raw integer value
    >> which (probably) isn't what the OP expects (assuming a 32 bit integer).
    >>
    >> Right?

    >
    > No. Completely wrong.


    Yup. No apologies. I looked through my nostrils on that one.
     
    Kleuskes & Moos, Dec 10, 2005
    #14
  15. In article <439af695$0$207$>,
    Thad Smith <> wrote:

    > Christian Bau wrote:
    > > In article <>,
    > > Roberto Waltman <> wrote:
    > >
    > >><> wrote:
    > >>Christian Bau wrote:
    > >>
    > >>>> Roberto Waltman <> wrote:
    > >>>>
    > >>>>>>int grid[1010][1010];
    > >>>>>>Which of the following is faster?
    > >>>>>>1. memset(grid,0,1010*1010);
    > >>>>>>2. memset(grid,0,sizeof(grid));
    > >>>>>
    > >>>>>You probably meant:
    > >>>>> 1. memset(grid,0,1010*1010*sizeof(int));
    > >>>>>Otherwise the two statements are not equivalent.
    > >>>>>
    > >>>>>I would expect a modern compiler to compute
    > >>>>>the result of "1010*1010*sizeof(int)" at compile
    > >>>>>time, therefore there would be no difference
    > >>>>>between 1. & 2.
    > >>>>
    > >>>>You are overlooking a small, but important detail, which doesn't only
    > >>>>affect execution speed, but also correctness.
    > >>>
    > >>>Great... I love puzzles.
    > >>>
    > >>>memset sets byte and will *incorrectly* chop 0x3F2 to 0xF2. Subsequent
    > >>>inspection of the array will then yield 0xF2F2F2F2 as raw integer value
    > >>>which (probably) isn't what the OP expects (assuming a 32 bit integer).
    > >>>
    > >>>Right?
    > >>
    > >>Wrong. And no puzzle here. Christian refers to the
    > >>fact that "memset(grid,0,sizeof(grid))" will always
    > >>have the correct size of grid, while the correctness
    > >>of the other statement depends on the programmer
    > >>updating it manually if the size of grid changes.

    > >
    > > Just to make sure we are talking about the same things:
    > >
    > >>>>>>int grid[1010][1010];
    > >>>>>>Which of the following is faster?
    > >>>>>>1. memset(grid,0,1010*1010);
    > >>>>>>2. memset(grid,0,sizeof(grid));

    > >
    > > 1. Contains an absolut blatant error that will make you wish you could
    > > disappear in the ground when you spot it. You are probably looking for
    > > some subtle mistake. There is nothing subtle about it.

    >
    > Sorry, Christian 2, you are wrong. Christian 1 saw the above
    >
    > >>>>>You probably meant:
    > >>>>> 1. memset(grid,0,1010*1010*sizeof(int));

    >
    > and took it into consideration when writing
    >
    > >>>>You are overlooking a small, but important detail, which doesn't
    > >>>>only affect execution speed, but also correctness.

    >
    > Christian 1 was therefore referring to the fact that sizeof(grid) is a
    > the correct size, while 1010*1010*sizeof(int) is evaluated as
    > (int)(1010*1010) * sizeof(int), which overflows in the case that an int
    > is 16 bits and size_t is properly sized to permit a declaration of
    > int grid[1010][1010];


    No, Christian suffered from a severe lack of concentration. The problem
    you spotted could have been used for some face saving, but I didn't spot
    it (and there were maybe five years where I used implementations where
    this would have been a problem, that is int = 16 bit and enough memory
    for 1010 x 1010 ints).
     
    Christian Bau, Dec 10, 2005
    #15
  16. Annajiat

    Thad Smith Guest

    Christian Bau wrote:
    > In article <>,
    > Roberto Waltman <> wrote:
    >
    >><> wrote:
    >>Christian Bau wrote:
    >>
    >>>> Roberto Waltman <> wrote:
    >>>>
    >>>>>>int grid[1010][1010];
    >>>>>>Which of the following is faster?
    >>>>>>1. memset(grid,0,1010*1010);
    >>>>>>2. memset(grid,0,sizeof(grid));
    >>>>>
    >>>>>You probably meant:
    >>>>> 1. memset(grid,0,1010*1010*sizeof(int));
    >>>>>Otherwise the two statements are not equivalent.
    >>>>>
    >>>>>I would expect a modern compiler to compute
    >>>>>the result of "1010*1010*sizeof(int)" at compile
    >>>>>time, therefore there would be no difference
    >>>>>between 1. & 2.
    >>>>
    >>>>You are overlooking a small, but important detail, which doesn't only
    >>>>affect execution speed, but also correctness.
    >>>
    >>>Great... I love puzzles.
    >>>
    >>>memset sets byte and will *incorrectly* chop 0x3F2 to 0xF2. Subsequent
    >>>inspection of the array will then yield 0xF2F2F2F2 as raw integer value
    >>>which (probably) isn't what the OP expects (assuming a 32 bit integer).
    >>>
    >>>Right?

    >>
    >>Wrong. And no puzzle here. Christian refers to the
    >>fact that "memset(grid,0,sizeof(grid))" will always
    >>have the correct size of grid, while the correctness
    >>of the other statement depends on the programmer
    >>updating it manually if the size of grid changes.

    >
    > Just to make sure we are talking about the same things:
    >
    >>>>>>int grid[1010][1010];
    >>>>>>Which of the following is faster?
    >>>>>>1. memset(grid,0,1010*1010);
    >>>>>>2. memset(grid,0,sizeof(grid));

    >
    > 1. Contains an absolut blatant error that will make you wish you could
    > disappear in the ground when you spot it. You are probably looking for
    > some subtle mistake. There is nothing subtle about it.


    Sorry, Christian 2, you are wrong. Christian 1 saw the above

    >>>>>You probably meant:
    >>>>> 1. memset(grid,0,1010*1010*sizeof(int));


    and took it into consideration when writing

    >>>>You are overlooking a small, but important detail, which doesn't
    >>>>only affect execution speed, but also correctness.


    Christian 1 was therefore referring to the fact that sizeof(grid) is a
    the correct size, while 1010*1010*sizeof(int) is evaluated as
    (int)(1010*1010) * sizeof(int), which overflows in the case that an int
    is 16 bits and size_t is properly sized to permit a declaration of
    int grid[1010][1010];

    Right?

    --
    Thad
     
    Thad Smith, Dec 10, 2005
    #16
  17. Annajiat

    Malcolm Guest

    "Annajiat" <> wrote
    Hi,
    >a)
    >int grid[1010][1010];
    >Which of the following is faster?
    >1. memset(grid,0,1010*1010);
    >2. memset(grid,0,sizeof(grid));


    Other people have pointed out this error.
    However with a million elements, any difference in the way you call the
    function will be totally trivial.

    > b) Is there any faster alternative to initializing memory?
    >

    Not in C. However you have over 4 million bytes to initialise. A lot of
    computers are equipped with hardware which can clear or transfer memory in
    parallel, and this may be the way to go.

    > c) What is the difference between comp.lang.c and alt.comp.lang.c ?
    >

    Dunno.
    > d) Is there any performance difference in local and global array?
    >

    Not really. It is a micro-optimisation problem. One some systems the global
    might be slightly faster (because of overhead in setting up the local
    array), on other systems the local may be slightly faster (maybe because the
    stack is more likely to be in the cache). But the difference is probably
    trivial in comparison to the algorithm you use to manipuate the array.
     
    Malcolm, Dec 10, 2005
    #17
  18. "Malcolm" <> writes:
    > "Annajiat" <> wrote
    > Hi,
    >>a)
    >>int grid[1010][1010];
    >>Which of the following is faster?
    >>1. memset(grid,0,1010*1010);
    >>2. memset(grid,0,sizeof(grid));

    >
    > Other people have pointed out this error.
    > However with a million elements, any difference in the way you call the
    > function will be totally trivial.
    >
    >> b) Is there any faster alternative to initializing memory?
    >>

    > Not in C. However you have over 4 million bytes to initialise. A lot of
    > computers are equipped with hardware which can clear or transfer memory in
    > parallel, and this may be the way to go.


    And if so, memset() may use it if the implementer has chosen to
    optimize it for a particular target CPU.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Dec 10, 2005
    #18
  19. Annajiat

    Malcolm Guest

    "Keith Thompson" <> wrote
    >> Not in C. However you have over 4 million bytes to initialise. A lot of
    >> computers are equipped with hardware which can clear or transfer memory
    >> in
    >> parallel, and this may be the way to go.

    >
    > And if so, memset() may use it if the implementer has chosen to
    > optimize it for a particular target CPU.
    >

    The problem is that, in ANSI C

    memset(array, 0, HUGE_NUMBER);
    if(array[index] == 0)
    {
    /* this condition must always be true */
    }

    However if the memory is being cleared in parallel, really you want to do
    something useful whilst the clear takes place.
     
    Malcolm, Dec 11, 2005
    #19
  20. Annajiat

    Eric Sosman Guest

    Malcolm wrote:

    > "Keith Thompson" <> wrote
    >
    >>>Not in C. However you have over 4 million bytes to initialise. A lot of
    >>>computers are equipped with hardware which can clear or transfer memory
    >>>in
    >>>parallel, and this may be the way to go.

    >>
    >>And if so, memset() may use it if the implementer has chosen to
    >>optimize it for a particular target CPU.
    >>

    >
    > The problem is that, in ANSI C
    >
    > memset(array, 0, HUGE_NUMBER);
    > if(array[index] == 0)
    > {
    > /* this condition must always be true */


    Only for suitable types of `array'.

    > }
    >
    > However if the memory is being cleared in parallel, really you want to do
    > something useful whilst the clear takes place.


    Sorry; nobody named "comp.programming.threads" lives
    here. You must have a wrong number.

    (More seriously, C's model of the computing universe is
    single-threaded and synchronous. If I were looking for things
    to parallelize in C, I'd not worry about memset() until after
    I'd done something about I/O.)

    --
    Eric Sosman
    lid
     
    Eric Sosman, Dec 11, 2005
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ham

    I need speed Mr .Net....speed

    Ham, Oct 28, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    2,359
    Antony Baula
    Oct 29, 2004
  2. efiedler
    Replies:
    1
    Views:
    2,088
    Tim Ward
    Oct 9, 2003
  3. Replies:
    2
    Views:
    2,316
    Howard
    Apr 28, 2004
  4. Replies:
    2
    Views:
    348
    Christopher Benson-Manica
    Apr 28, 2004
  5. Weng Lei-QCH1840
    Replies:
    1
    Views:
    192
    Thomas
    Aug 15, 2003
Loading...

Share This Page