How to Check the content of the memory?

Discussion in 'C++' started by RJ, Dec 15, 2005.

  1. RJ

    RJ Guest

    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
     
    RJ, Dec 15, 2005
    #1
    1. Advertising

  2. 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
     
    Neelesh Bodas, Dec 15, 2005
    #2
    1. Advertising

  3. RJ

    mlimber Guest

    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
     
    mlimber, Dec 15, 2005
    #3
  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?
    >
    > Any suggestion!!
    >
    > Thanks,
    > Raja
     
    Neelesh Bodas, Dec 15, 2005
    #4
  5. 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
     
    Neelesh Bodas, Dec 15, 2005
    #5
  6. RJ

    RJ Guest

    >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
     
    RJ, Dec 16, 2005
    #6
  7. RJ

    RJ Guest

    >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?
     
    RJ, Dec 16, 2005
    #7
  8. RJ

    Guest

    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, 2005
    #8
  9. RJ

    mlimber Guest

    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
     
    mlimber, Dec 16, 2005
    #9
  10. RJ

    Jim Langston Guest

    "RJ" <> wrote in message
    news:...
    > 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.
     
    Jim Langston, Dec 18, 2005
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J.Edwards
    Replies:
    0
    Views:
    1,702
    J.Edwards
    Jan 20, 2006
  2. TheKeith
    Replies:
    20
    Views:
    107,206
    Chris Morris
    Oct 29, 2003
  3. hazz
    Replies:
    6
    Views:
    50,063
    SkyUCHC
    Jun 9, 2010
  4. Stanimir Stamenkov
    Replies:
    2
    Views:
    795
    Stanimir Stamenkov
    Oct 25, 2005
  5. Replies:
    0
    Views:
    760
Loading...

Share This Page