473,789 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fast check for binary zeroes in memory

hi folks,

is there a fast way to check for large regions of binary zeroes in
memory? the solution could be either in C or in assemble language? i
am interested in any RISC platforms.

TIA,

vrigo
Nov 14 '05 #1
7 2654
"vrigo" <vr*******@gmai l.com> wrote in message
news:e9******** *************** **@posting.goog le.com...
is there a fast way to check for large regions of binary zeroes in
memory?
The only method available in standard C is to do it a byte at a time, with a
pointer to unsigned char.

Platform-specific methods may perform better. After ensuring
platform-specific alignment, you can use a platform-specific larger data
type that has no padding bits.
the solution could be either in C or in assemble language? i am
interested in any RISC platforms.


If the platform is relevant to your question, then this is the wrong place
to ask: find a group for that platform.

If you are asking how to get the best performance for some operation, then
this is the wrong place to ask: it's either an algorithm question (find a
group relating to the problem domain, or try comp.programmin g), or the
platform is relevant and the previous case applies.

Alex
Nov 14 '05 #2
In 'comp.lang.c', vr*******@gmail .com (vrigo) wrote:
is there a fast way to check for large regions of binary zeroes in
memory? the solution could be either in C or in assemble language? i
am interested in any RISC platforms.


memcmp();

a loop.

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #3
In <Xn************ *************** @212.27.42.71> Emmanuel Delahaye <em**********@n oos.fr> writes:
In 'comp.lang.c', vr*******@gmail .com (vrigo) wrote:
is there a fast way to check for large regions of binary zeroes in
memory? the solution could be either in C or in assemble language? i
am interested in any RISC platforms.


memcmp();


To be of any use, you already need to have an equally large memory block
that is already zeroed.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #4
In <e9************ *************@p osting.google.c om> vr*******@gmail .com (vrigo) writes:
is there a fast way to check for large regions of binary zeroes in
memory? the solution could be either in C or in assemble language? i
am interested in any RISC platforms.


The fastest solution can be obtained in assembly, but this is not
something we can discuss here, and it's higly processor specific, anyway.

At C level, it's easier if the region is aligned for long access, but you
can do the alignment yourself, by converting the pointer to an unsigned
long, aligning the integer value and then converting it back to a
pointer. Do the testing accessing as much as possible of the memory
block as an array of unsigned long and test the first and the last
few bytes as unsigned char, if necessary. As unsigned long has the same
size as the processor word on any decent implementation for RISC
platforms, this is the best you can do, in C code. If the chances that
the memory block is zeroed are high, you may try OR-ing all the words
together in a loop and only testing the final result.

Ignore any objections other people might raise about padding bits:
they have yet to be seen on any RISC platform. And the unsigned integer
types are immune from any dual representation of the zero value (in the
absence of padding bits).

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #5
Dan Pop wrote:
In <Xn************ *************** @212.27.42.71> Emmanuel Delahaye <em**********@n oos.fr> writes:

In 'comp.lang.c', vr*******@gmail .com (vrigo) wrote:

is there a fast way to check for large regions of binary zeroes in
memory? the solution could be either in C or in assemble language? i
am interested in any RISC platforms.


memcmp();

To be of any use, you already need to have an equally large memory block
that is already zeroed.


You snipped the words that followed "memcmp();" ,
which were "a loop." Begin by establishing that the
first N bytes are all zero -- use a smallish known-zero
block, or start with N=1 and a simple `=='. Then use
memcmp() to compare the first N bytes to the second N,
establishing (or disproving) that the first 2N bytes
are all zero. Then compare the first 2N to the second
2N to extend to 4N, and so on. The edge conditions
take a wee bit of care, but it's not complicated.

I used a similar technique in a function that fills
a memory area with copies of a multi-byte object, rather
like memset() but without the limitation of a single-byte
value. The loop uses memcpy() instead of memcmp(), of
course, but the outline is similar. <OT>And it doesn't
thrash the cache, either, although I was half expecting
it to do so.</OT>

--
Er*********@sun .com

Nov 14 '05 #6
In <40************ **@sun.com> Eric Sosman <Er*********@su n.com> writes:
Dan Pop wrote:
In <Xn************ *************** @212.27.42.71> Emmanuel Delahaye <em**********@n oos.fr> writes:

In 'comp.lang.c', vr*******@gmail .com (vrigo) wrote:
is there a fast way to check for large regions of binary zeroes in
memory? the solution could be either in C or in assemble language? i
am interested in any RISC platforms.

memcmp();

To be of any use, you already need to have an equally large memory block
that is already zeroed.


You snipped the words that followed "memcmp();" ,
which were "a loop."


I took it as being another alternative solution, not as part of a single
solution.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #7
Thanks for all the answers :-) For processor specific answers I will
also post the query to appropriate news group. Thanks again.
Nov 14 '05 #8

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

Similar topics

25
3660
by: Gaurav Verma | last post by:
Hi, I want to convert a floating point number (or a decimal number say 123.456) into binary notation using a C program. Can somebody help me out with it? Thanks Gaurav -- comp.lang.c.moderated - moderation address: clcm@plethora.net
20
9177
by: GS | last post by:
The stdint.h header definition mentions five integer categories, 1) exact width, eg., int32_t 2) at least as wide as, eg., int_least32_t 3) as fast as possible but at least as wide as, eg., int_fast32_t 4) integer capable of holding a pointer, intptr_t 5) widest integer in the implementation, intmax_t Is there a valid motivation for having both int_least and int_fast?
6
34810
by: ron | last post by:
Hi, I am having some issues converting a binary string value to a hex string value. Example: string mybinary = "0000111111111000"; string myhex = Convert.ToString(Convert.ToInt32(mybinary, 2), 16); returns: "FF8"
17
4672
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some analysis and I'm led to believe (but can't yet quantitatively establish as fact) that the two basic culprits are a lot of calls to: 1.) if( someString.ToLower() == "somestring" ) and
2
2255
by: testrasbath | last post by:
Why strings are not getting converted to binary form, even if we use BinaryWriter for writing to a file? Which is the similar technique in c# as ifstream(filename, ios::binary) in C++? My Code: int version = 1024; string loginname = "test";
6
3398
by: Dan Henry | last post by:
I need a sanity check. The following is an exchange on comp.arch.embedded with CBFalconer in a rather long MISRA related thread. Since my little section of that thread and area of interest was never really about MISRA, but rather the one's complement representation of integer constant 0 and now how to zero memory portably, I am bringing the topic to this group. Try to ignore CBF's errors in the 1's complement -1 and sign magnitude -1...
3
569
by: email.ttindustries | last post by:
Hello, I am a C/C++ newbie and I have a simple question concerning fast data writing to binary files. Are there any other faster methods than the standard write() method to write to binary data files? I ask this question because I have to store a big amount of data coming from an PCI A/D card with a sampling frequency of 20 MB/s. Now I have to implement some additional computations and would need to speed up the data transfer. I am...
6
5246
by: aagarwal8 | last post by:
Hi, I am trying to write the contents of a textbox to a file in binary format. My code looks like this... private void btnWriteToFile_Click(object sender, EventArgs e) { FileStream fs = File.Open(@"D:\test.dat", FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs);
5
2588
by: Canned | last post by:
Hi, I'm trying to write a class that can convert ascii to binary and vice versa. I write my class based on this function I've found on internet That works perfectly, but when I try to implement it in my own class it gives me alot of headache, also because I'm totally new to the language. It work only with one character at a time, and if I give a string it just give some weird result.
0
9657
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
10393
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10187
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10132
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
9974
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
9007
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...
0
6753
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2902
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.