473,573 Members | 2,932 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding the size of binary data stored in memory

Hi

A separte application is sending me a pointer to some binary data and I
need to find the size of the binary data being passed to me. Does
anyone know I can go about doing this?

TIA

Dec 4 '06 #1
6 3033
"sajohn" <sa******@yahoo .comwrites:
>A separte application is sending me a pointer to some binary data and I
need to find the size of the binary data being passed to me. Does
anyone know I can go about doing this?
Not generally possible without you knowing how to interpret the data.
The application itself will also need to send you the length of the data.

--
Chris.
Dec 4 '06 #2
"sajohn" <sa******@yahoo .comwrites:
A separte application is sending me a pointer to some binary data and I
need to find the size of the binary data being passed to me. Does
anyone know I can go about doing this?
In the most general case, the software that is passing you the
pointer must tell you how much data it is passing. In more
specific cases, that might not be necessary. Perhaps you can
tell us more about your case.
--
"For those who want to translate C to Pascal, it may be that a lobotomy
serves your needs better." --M. Ambuhl

"Here are the steps to create a C-to-Turbo-Pascal translator..." --H. Schildt
Dec 4 '06 #3
In article <11************ **********@16g2 000cwy.googlegr oups.com>,
sajohn <sa******@yahoo .comwrote:
>A separte application is sending me a pointer to some binary data and I
need to find the size of the binary data being passed to me. Does
anyone know I can go about doing this?
C doesn't provide a way to do that. You'll have to get the
application (presumably you mean some other code in the same program,
since it's passing a pointer) to tell you, or encode the information
in the data itself.

-- Richard

--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Dec 4 '06 #4
"sajohn" <sa******@yahoo .comwrites:
A separte application is sending me a pointer to some binary data and I
need to find the size of the binary data being passed to me. Does
anyone know I can go about doing this?
You'll have to be more specific; showing us some actual code would be
a good start.

In general, a separate application (a separately running program)
can't send a meaningful pointer to another application (though there
may be some extremely system-specific tricks you can play with shared
memory). Is the pointer coming from a separate application, or from,
say, a library that your application is using?

C pointers are typed, meaning that when you declare a pointer, you
have to specify what type it points to. That gives you the size of
the pointed-to data (sizeof *ptr), but that's a fixed size, and I
suspect it's not what you want.

More commonly, a pointer points to (the first element of) an array of
some type. There's no general way to get the size of the array given
the value of the pointer. You have to get the information in some
other way. For example, a function can take two arguments, a pointer
and an integer (size_t?) indicating the length of the array. Or you
can have a sentinel value that marks the end of the array (C strings
use '\0' for this).

We can't give you any more specific advice without more specific
information.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 5 '06 #5
Keith Thompson wrote:
"sajohn" <sa******@yahoo .comwrites:
A separte application is sending me a pointer to some binary data and I
need to find the size of the binary data being passed to me. Does
anyone know I can go about doing this?
<snip>
In general, a separate application (a separately running program)
can't send a meaningful pointer to another application (though there
may be some extremely system-specific tricks you can play with shared
memory).
<snip>

On systems without virtual memory, (or other forms of memory
protection), pointers could easily be valid, even useful, across
processes.

Real-mode DOS comes to mind.

Dec 5 '06 #6
santosh wrote:
On systems without virtual memory, (or other forms of memory
protection), pointers could easily be valid, even useful, across
processes.

Real-mode DOS comes to mind.
Or the Amiga, which relied heavily on being able to do this.

- Ernie http://home.comcast.net/~erniew

Dec 5 '06 #7

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

Similar topics

13
15212
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the pattern can occur on any byte boundary in the file, so chunking through the code at 16 bytes a frame maybe a problem. The file itself isn't so large,...
2
28555
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
11
4270
by: Bill Cunningham | last post by:
In fread, the type of the function is the typedef size_t. I want to rewrite a program that read binary data of mp3s. int main(){ printf("Enter name of file-> "); char name; fflush(stdout); FILE *fp; fp=fopen(name,"rb"); /*Here's where fread should go but k&r p 248 didn't help much */ fclose(fp);}
5
4764
by: Hongzheng Wang | last post by:
Hi, everyone I have a problem about malloc/free function. Does malloc add size information to program? And, when free function is called, how this function get the size information? That is, if I request a memory block of size 10, where the size information 10 is stored? To be clear, I have such codes below: int *p = (int *)...
17
15958
by: Arnold | last post by:
Is using fseek and ftell a reliable method of getting the file size on a binary file? I thought I remember reading somewhere it wasn't... If not what would be the "right" and portable method to obtain it? Thanks.
6
7560
by: Tarun | last post by:
Hi All, I need to find a particular substring in a binary string(some text appended & prepended to binary data). I cant use strstr since it terminates on receiving '\0'which can be there in binary data also I cant use memmem. Is there any other available function to do this. Regards Tarun
14
2744
by: googler | last post by:
Is there any C library function that returns the size of a given file? Otherwise, is there a way in which file size can be determined in a C program? I need to get this for both Linux and Windows platforms, so a generic solution is what I am looking for. Thanks for your help.
8
564
by: Dave | last post by:
I am serialising an object to a memory mapped file (using the CreateFileMapping and MapViewOfFile p/invoke calls). These need to know the maximum size of the "file". I can put in a "good guess" ie it won't be more than, say, 1K, but it would be tidier to use the actaul size. Is it actually possible to find out how big an object (or even...
275
12140
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
7781
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...
0
8027
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. ...
0
8202
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...
0
8066
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...
1
5594
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...
0
5292
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...
0
3733
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2216
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1041
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...

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.