473,569 Members | 2,458 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 3031
"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
15210
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
28546
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
4763
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
7559
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
2739
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
12117
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
7703
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
7618
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...
0
8138
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...
1
7679
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...
0
7983
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...
0
6287
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...
1
5514
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...
1
2117
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
946
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.