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

How to Check the content of the memory?

P: n/a
RJ
Hi All,

Suppose i have a double pointer, how do I check the content of that
pointer is a 8/16/24/32 bit data?

Any suggestion!!

Thanks,
Raja

Dec 15 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a

RJ wrote:
Hi All,

Suppose i have a double pointer, how do I check the content of that
pointer is a 8/16/24/32 bit data?

Any suggestion!!


double *d;
sizeof(*d); // size in bytes
sizeof(*d) * CHAR_BITS // size in bits

Dec 15 '05 #2

P: n/a
RJ wrote:
Suppose i have a double pointer, how do I check the content of that
pointer is a 8/16/24/32 bit data?


Please clarify:

When you say "double pointer", do you mean double* or something like
int**? If the former, double can be other sizes, too (e.g., 64 bit
data).

When you say "check the content of that pointer", do you mean check the
size of the data it points to, check the address contained by the
pointer itself, or check the value of the data it points to?

In any case, the size of built-in types (ints, doubles, pointers, etc.)
are implementation-specific, and you should check your platform
documentation to see what the sizes are in your case.

Cheers! --M

Dec 15 '05 #3

P: n/a

RJ wrote:
Hi All,

Suppose i have a double pointer, how do I check the content of that
pointer is a 8/16/24/32 bit data?

Any suggestion!!

Thanks,
Raja


Dec 15 '05 #4

P: n/a
RJ wrote:
Hi All,

Suppose i have a double pointer, how do I check the content of that
pointer is a 8/16/24/32 bit data?

double *p;
sizeof(*p); // returns the number of bytes
sizeof(*p) * CHAR_BITS // returns the size in bits

Dec 15 '05 #5

P: n/a
RJ
>When you say "double pointer", do you mean double* or something like
int**? If the former, double can be other sizes, too (e.g., 64 bit
data).
Sorry for the confusion. Its a double* p.
When you say "check the content of that pointer", do you mean check the
size of the data it points to, check the address contained by the
pointer itself, or check the value of the data it points to?


For example,

unsigned long* lp=0xFFF;
if I have RGB value in *lp and the RGB is 444 format. Only 12 bits are
used out of 32 bit. Remaining 20 bits padded with 0.

unsigned long* lp=0xFFFFFF;
Like if i have RGB of 888, then only 24 bit used and remaining 8 bits
padded with 0.

So my question is how to find a pointer content is used only 'n' number
of bytes and remaining 'm' number of bytes are padded to 0.
ie.,In generic how to calculate n and m?

Thanks again.
Raja

Dec 16 '05 #6

P: n/a
RJ
>So my question is how to find a pointer content is used only 'n' number
of bytes and remaining 'm' number of bytes are padded to 0.
ie.,In generic how to calculate n and m?


So my question is how to find a pointer content is used only 'n' number

of bits remaining 'm' number of bits are padded to 0.
ie.,In generic how to calculate n and m?

Dec 16 '05 #7

P: n/a
RJ wrote:
unsigned long* lp=0xFFF;
if I have RGB value in *lp and the RGB is 444 format. Only 12 bits are
used out of 32 bit. Remaining 20 bits padded with 0.


Sure, but what if you have black? That's 0x000. 12 bits used, but those
bits are just as 0 as the other 20 bits.

In general, you can't. You can check the number of bits in the format
mask, if such a thing exists. The number of bits in x, nb(x) is found
by nb(x) = x%2 + nb(x/2).

HTH,
Michiel Salters

Dec 16 '05 #8

P: n/a
RJ wrote:
When you say "double pointer", do you mean double* or something like
int**? If the former, double can be other sizes, too (e.g., 64 bit
data).


Sorry for the confusion. Its a double* p.


First of all, the fact that it's a pointer (whether of type double* or
unsigned long* or whatever) is irrelevant based on what you say below.
You seem to care about the pointee, not the pointer.

In the case of doubles, the floating point format is
implementation-dependent. There are a certain number of bits allocated
for the exponent and a certain number for the mantissa, but those
numbers are not standard. Check your platform documentation for the
floating point format.
When you say "check the content of that pointer", do you mean check the
size of the data it points to, check the address contained by the
pointer itself, or check the value of the data it points to?


For example,

unsigned long* lp=0xFFF;
if I have RGB value in *lp and the RGB is 444 format. Only 12 bits are
used out of 32 bit. Remaining 20 bits padded with 0.

unsigned long* lp=0xFFFFFF;
Like if i have RGB of 888, then only 24 bit used and remaining 8 bits
padded with 0.

So my question is how to find a pointer content is used only 'n' number
of bytes and remaining 'm' number of bytes are padded to 0.
ie.,In generic how to calculate n and m?


As the other responder pointed out, you might get into trouble with
certain values, depending on how you use the number of non-zero bits.
Usually, in image processing applications, you just need to keep track
of how many bits are valid and only work on those. That means that you
may need to pass a mask or bit count (and perhaps other relevant
information) around to your functions along with the pixels, but that's
just part of the game.

In case you do have a legitimate use for such information, you can
easily calculate it:

unsigned CountBitsUsed( unsigned long val )
{
for( int n=sizeof(unsigned long)-1; n > 0; --n )
if( 0 != (val & (1<<n)) )
return n+1;
return 0;
}

Cheers! --M

Dec 16 '05 #9

P: n/a
"RJ" <ra*******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi All,

Suppose i have a double pointer, how do I check the content of that
pointer is a 8/16/24/32 bit data?

Any suggestion!!

Thanks,
Raja


What you seem to be asking (after reading the follow ups) is if you have a
pointer to some unknown data, how can you find out what the size is of the
unknown data.

Basically, the pointer won't tell you. The pointer points to a spot in
memory. How you declare the pointer suggests what type of data should be
there. That is, if you have an int* it should be pointing to an integer
value which is x bytes on your platform.

But you seem to be specifically interested in video memory, RGB data. Well,
this totally depends on the format of the data you are looking at. If you
are looking at video memory, it depends on what display resolution your
monitor video card is set to. If you are looking at bitmap information, it
would depend on the format of the bitmap.

For video memory, you need to find out the resolution the video card is
currently set to. This is dependant on your OS. For bitmap information, it
depends on the format of the bitmap. I believe this is also OS independant.

Dec 18 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.