473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to Check the content of the memory?

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
9 2476

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

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
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
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
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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Randell D. | last post by:
Folks, I've heard of buffer overflows being used/abused by hackers and believe one method to reduce this from happening is to check the length of my form data before writing it to my MySQL...
2
by: shyamal | last post by:
I want to display memory content using C++ on LINUX. For example, the user may ask to display 256 bytes from 0x1000ff00. The problem is , if any location is invalid, the program will coredump...
20
by: Jonas | last post by:
Hi, I'm 99 % sure that Standard C guarantees to do a memory move inside realloc() in case the new, returned memory block (address) is different than the original one. Can any C expert confirm...
4
by: VR | last post by:
I am trying to embed a check box into a FlexGrid's cell, but having a problem when I start scrolling the grid. Here is my MyCheckBox class... class MyCheckBox : CheckBox { void Init (...
11
by: zhong | last post by:
Error Message: Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention...
3
by: TK | last post by:
Excuse me for multiple posting because I've posted this message to aspnet.security NG but have not got any response yet. I'm building an ASP.NET application works in Forms Authentication mode...
7
by: yancheng.cheok | last post by:
hello all, in my memory content says, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8 ... 0xff i wish to shift it n bits. please note that, not n bye, but n bit, and n can be any value 0, 1,...
0
by: Vincent | last post by:
Dear all, I have implemented a class to export the content of RichTextBox to image in WYSISYG mode so that line breaks on the screen are the same as exported. C# Code: public struct...
173
by: Marty James | last post by:
Howdy, I was reflecting recently on malloc. Obviously, for tiny allocations like 20 bytes to strcpy a filename or something, there's no point putting in a check on the return value of malloc....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.