Memset Optimizing

Discussion in 'C Programming' started by prcpani@polaris.co.in, Jun 24, 2005.

  1. Guest

    I have a program that will read as follows


    #define MS(x) memset(x.arr,'\0',sizeof(x.arr­))


    void memset_var()
    {
    int cnt =0;


    for (cnt=0;cnt<ARR_SIZE;cnt++)
    {
    MS(v_array_temp[cnt]);
    }



    }


    How do i avoid loop and is there any short cut or easier method to
    clear the array without using loop
    , Jun 24, 2005
    #1
    1. Advertising

  2. Eric Sosman Guest

    wrote:
    > I have a program that will read as follows
    >
    >
    > #define MS(x) memset(x.arr,'\0',sizeof(x.arr­))
    >
    > void memset_var()
    > {
    > int cnt =0;
    > for (cnt=0;cnt<ARR_SIZE;cnt++)
    > {
    > MS(v_array_temp[cnt]);
    > }
    > }
    >
    > How do i avoid loop and is there any short cut or easier method to
    > clear the array without using loop


    You haven't given enough information. How is
    `v_array_temp' declared?

    --
    Eric Sosman
    lid
    Eric Sosman, Jun 24, 2005
    #2
    1. Advertising

  3. Guest

    Eric Sosman wrote:
    > wrote:
    > > I have a program that will read as follows
    > >
    > >
    > > #define MS(x) memset(x.arr,'\0',sizeof(x.arr­))
    > >
    > > void memset_var()
    > > {
    > > int cnt =0;
    > > for (cnt=0;cnt<ARR_SIZE;cnt++)
    > > {
    > > MS(v_array_temp[cnt]);
    > > }
    > > }
    > >
    > > How do i avoid loop and is there any short cut or easier method to
    > > clear the array without using loop

    >
    > You haven't given enough information. How is
    > `v_array_temp' declared?
    >
    > --
    > Eric Sosman
    > lid



    v_array_temp VARCHAR[ARR_SIZE][11];

    this is Pro*C program that declare a cursor and fetch the column value
    into v_array_temp. if ARR_SIZE is 4000 then 4000 records are fetched
    into this variable and we manipulate the same and use bulk update to
    update the new values from that v_array_temp variable. loop continues
    after the update by calling memset_var() to clear the array and fetch
    another 4000 records to do the process of fetching and updating till
    End of Records in the table.

    Hope this information is clear. please help me to avoid loop to clear
    the variable. please let me know is there any shortcut or single line
    statement to clear the VARCHAR array.
    , Jun 27, 2005
    #3
  4. Guest

    VARCHAR v_array_temp[ARR_SIZE][11];

    This is Pro*C program to clear the array and fetch records and then
    manipulate and then do bulk update. after that i have to use
    memset_var() to clear the array and fetch another set of records.
    , Jun 27, 2005
    #4
  5. Michael Mair Guest

    wrote:
    > Eric Sosman wrote:
    >
    >> wrote:
    >>
    >>>I have a program that will read as follows
    >>>
    >>>
    >>>#define MS(x) memset(x.arr,'\0',sizeof(x.arr­))
    >>>
    >>>void memset_var()
    >>>{
    >>> int cnt =0;
    >>> for (cnt=0;cnt<ARR_SIZE;cnt++)
    >>> {
    >>> MS(v_array_temp[cnt]);
    >>> }
    >>>}
    >>>
    >>>How do i avoid loop and is there any short cut or easier method to
    >>>clear the array without using loop

    >>
    >> You haven't given enough information. How is
    >>`v_array_temp' declared?
    >>
    >>--
    >>Eric Sosman
    >>

    >

    [snip]
    ,-- replaced by content of other reply ---
    | VARCHAR v_array_temp[ARR_SIZE][11];
    |
    | This is Pro*C program to clear the array and fetch records and then
    | manipulate and then do bulk update. after that i have to use
    | memset_var() to clear the array and fetch another set of records.
    `----
    >
    > this is Pro*C program that declare a cursor and fetch the column value
    > into v_array_temp. if ARR_SIZE is 4000 then 4000 records are fetched
    > into this variable and we manipulate the same and use bulk update to
    > update the new values from that v_array_temp variable. loop continues
    > after the update by calling memset_var() to clear the array and fetch
    > another 4000 records to do the process of fetching and updating till
    > End of Records in the table.
    >
    > Hope this information is clear. please help me to avoid loop to clear
    > the variable. please let me know is there any shortcut or single line
    > statement to clear the VARCHAR array.


    The problem is that you still do not tell enough about v_array_temp:
    We need the definition of VARCHAR and recursively everything that
    is not a standard C type.
    Apart from that, the above declaration of v_array_temp will not
    work in conjunction with MS as v_array_tmp[cnt].arr does not make
    sense for an array ARR_SIZE of an array 11 of VARCHAR.

    If VARCHAR is some kind of structure type intended as wrapper
    for strings you _might_ get lucky and can memset() everything
    to zero.

    Just give us enough information :)

    BTW: Another strategy to have less function calls for an array
    of objects you cannot initialise via memset() is using memcpy()
    in a loop and doubling the number of copied objects. However,
    this is potentially error prone compaired to a plain loop
    and has a certain overhead, so it may be less efficient due to
    this overhead. Another thing is that the compiler can easier
    find a suitable optimisation strategy (maybe even the above)
    if you give it a plain loop.


    Cheers
    Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
    Michael Mair, Jun 27, 2005
    #5
  6. On Mon, 27 Jun 2005 07:37:27 +0200, Michael Mair
    <> wrote:

    > wrote:
    > [snip]
    > ,-- replaced by content of other reply ---
    > | VARCHAR v_array_temp[ARR_SIZE][11];
    > |
    > | This is Pro*C program to clear the array and fetch records and then
    > | manipulate and then do bulk update. after that i have to use
    > | memset_var() to clear the array and fetch another set of records.
    > `----
    > >

    OP: Are you sure? Any sensible fetch logic should return the count of
    rows fetched; just do your processing loop(s) up to that count.

    > > this is Pro*C program that declare a cursor and fetch the column value
    > > into v_array_temp. if ARR_SIZE is 4000 then 4000 records are fetched
    > > into this variable and we manipulate the same and use bulk update to
    > > update the new values from that v_array_temp variable. loop continues
    > > after the update by calling memset_var() to clear the array and fetch
    > > another 4000 records to do the process of fetching and updating till
    > > End of Records in the table.
    > >
    > > Hope this information is clear. please help me to avoid loop to clear
    > > the variable. please let me know is there any shortcut or single line
    > > statement to clear the VARCHAR array.

    >
    > The problem is that you still do not tell enough about v_array_temp:
    > We need the definition of VARCHAR and recursively everything that
    > is not a standard C type.
    > Apart from that, the above declaration of v_array_temp will not
    > work in conjunction with MS as v_array_tmp[cnt].arr does not make
    > sense for an array ARR_SIZE of an array 11 of VARCHAR.
    >

    I can't say for Pro*C in particular, but in SQL VARCHAR(n) is a string
    of length variable up to the given limit, often mapped to something
    like struct VARCHAR20 { short len; char arr [20]; } or perhaps 21 to
    allow a C null-byte-terminator _in addition_. (Note len needn't be
    size_t since the precompiler knows a much smaller bound on it than
    "any possible object size"; but it might still be for convenience.)

    > If VARCHAR is some kind of structure type intended as wrapper
    > for strings you _might_ get lucky and can memset() everything
    > to zero.
    >

    <snip good general ideas>

    - David.Thompson1 at worldnet.att.net
    Dave Thompson, Jul 4, 2005
    #6
    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. k-man
    Replies:
    4
    Views:
    4,526
    Shelley Hebert
    Dec 18, 2003
  2. Joe C
    Replies:
    5
    Views:
    8,859
    tom_usenet
    Aug 24, 2004
  3. Replies:
    17
    Views:
    6,498
    Greg Comeau
    Sep 22, 2004
  4. Guest
    Replies:
    0
    Views:
    394
    Guest
    Sep 23, 2004
  5. Guest
    Replies:
    1
    Views:
    426
    Ron Natalie
    Sep 23, 2004
Loading...

Share This Page