Finding the size of binary data stored in memory

S

sajohn

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
 
B

Ben Pfaff

sajohn said:
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.
 
C

Chris McDonald

sajohn said:
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.
 
R

Richard Tobin

sajohn said:
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
 
K

Keith Thompson

sajohn said:
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.
 
S

santosh

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top