By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,276 Members | 1,494 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,276 IT Pros & Developers. It's quick & easy.

Finding the size of binary data stored in memory

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
"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

P: n/a
"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

P: n/a
In article <11**********************@16g2000cwy.googlegroups. 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

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Dec 4 '06 #4

P: n/a
"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_Keith) 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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.