473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Memset Optimizing

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

Nov 15 '05 #1
5 2825
pr*****@polaris.co.in 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
es*****@acm-dot-org.invalid

Nov 15 '05 #2
Eric Sosman wrote:
pr*****@polaris.co.in 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
es*****@acm-dot-org.invalid

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.

Nov 15 '05 #3
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.

Nov 15 '05 #4
pr*****@polaris.co.in wrote:
Eric Sosman wrote:
pr*****@polaris.co.in 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
es*****@acm-dot-org.invalid

[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.
Nov 15 '05 #5
On Mon, 27 Jun 2005 07:37:27 +0200, Michael Mair
<Mi**********@invalid.invalid> wrote:
pr*****@polaris.co.in 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
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mantorok Redgormor | last post by:
When is it that memset caused problems? I recall from posts in the past where someone used memset in their code that invoked undefined behavior. What about the following? char the_array; ...
6
by: bob_jenkins | last post by:
{ const void *p; (void)memset((void *)p, ' ', (size_t)10); } Should this call to memset() be legal? Memset is of type void *memset(void *, unsigned char, size_t) Also, (void *) is the...
26
by: 69dbb24b2db3daad932c457cccfd6 | last post by:
Hello, I have to initialize all elements of a very big float point array to zero. It seems memset(a, 0, len) is faster than a simple loop. I just want to know whether it is safe to do so, since I...
21
by: jacob navia | last post by:
Many compilers check printf for errors, lcc-win32 too. But there are other functions that would be worth to check, specially memset. Memset is used mainly to clear a memory zone, receiving a...
14
by: Patrick Kowalzick | last post by:
Dear all, I have an existing piece of code with a struct with some PODs. struct A { int x; int y; };
27
by: volunteers | last post by:
I met a question about memset and have no idea right now. Could anybody give a clue? Thanks memset is sometimes used to initialize data in a constructor like the example below. What is the...
23
by: AndersWang | last post by:
Hi, dose anybody here explain to me why memset would be faster than a simple loop. I doubt about it! In an int array scenario: int array; for(int i=0;i<10;i++) //ten loops
18
by: dykeinthebox | last post by:
Consider the following program: #include <stdlib.h> #include <string.h> int main( void ) { void *p = malloc( 4 ); if ( p ) {
18
by: Gaijinco | last post by:
I'm having a headache using memset() Given: int v; memset((void*)v, 1, sizeof(v)); Can I be 100% positive than v = 1 for i 0, or there is something else I have to do?.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.