Thread: pointer specific

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    12

    pointer specific [solved]

    how to wrap pointers?

    do i need to align pointer in memory (by padding or something)?

    i have array table of chars.
    example char array[65536).

    making:
    char *ptr = array;

    //in some loop (this dont work)
    *ptr += some_number;
    *ptr &= 0xffff; //modulu 65535+1

    //this work, but no pointer used
    value = array[index++ & 0xffff];

    ideas for pointer wrapping?
    Last edited by c coder; 06-11-2012 at 07:38 AM.

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    > modulu 65535+1
    That trick only works when you're trying to modulus by a power of two, then it's that number minus one.

    > do i need to align pointer in memory
    No. There's hardly ever a reason to force a pointer to alignment, unless it's for the purpose of optimization (usually only applicable in assembly). Otherwise, the computer will take care of this with caching and other mechanisms designed to keep access aligned.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to c++ some specific questions, gui, db, xml
    By bpr in forum C++ Programming
    Replies: 4
    Last Post: 01-12-2010, 12:48 PM
  2. Replies: 3
    Last Post: 10-30-2009, 04:41 PM
  3. Replies: 4
    Last Post: 08-27-2007, 11:51 PM
  4. Pointer to specific memory address
    By elnerdo in forum C++ Programming
    Replies: 10
    Last Post: 05-19-2006, 07:35 AM
  5. Platform Specific...
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 09-29-2002, 01:48 AM

Tags for this Thread