473,805 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2855
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*****@polar is.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**********@i nvalid.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.ne t
Nov 15 '05 #6

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

Similar topics

2
4069
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; memset(the_array, 'A', sizeof the_array);
6
8266
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 generic pointer type. My real question is, is (void *) such a generic pointer type that it
26
26238
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 know it's danger to initialize NULL pointers this way. But how about floats? Zhang Le
21
8796
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 pointer to the start, the value (most of the time zero) and the size of the memory array to clear. Problems appear when the size given is not the size of the object given as its first argument. For instance void fn(void)
14
8485
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
5238
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 benefit of initializing this way? Does it work in this example? Does it work in general ? Is it a good idea in general? class A { public:
23
13337
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
11991
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
783
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
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9185
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.