How to Check the content of the memory?

R

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
 
N

Neelesh Bodas

RJ said:
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
 
M

mlimber

RJ said:
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
 
N

Neelesh Bodas

RJ said:
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
 
N

Neelesh Bodas

RJ said:
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
 
R

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
 
R

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?
 
M

Michiel.Salters

RJ said:
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
 
M

mlimber

RJ said:
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.
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
 
J

Jim Langston

RJ said:
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.
 

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,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top