Memset Optimizing

P

prcpani

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
 
E

Eric Sosman

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?
 
P

prcpani

Eric said:
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?


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.
 
P

prcpani

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.
 
M

Michael Mair

Eric said:
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?
[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
 
D

Dave Thompson

(e-mail address removed) 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top