Thread: The Buddy System

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    3

    The Buddy System

    This is more of a general programming question than a C specific question, but can anyone explain to me how exactly the binary buddy system works?

    I.e., Two memory addresses: how can I tell if they are buddies or not given a size I am looking for? (128K, 256K, etc).

    I know I need to use some sort of bit masking but I am unsure how to go about it.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    3
    I understand how it actually works, that's not the problem. It's how exactly to identify which blocks are buddies based on the memory address is what is confusing me.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    3
    I figured this out on my own, but just in case anyone ever has the same problem and searches the forums:

    Say you have memory *offsets* of X and Y and you want to test to see if they are buddies of size S, where S must be a power of two. Buddies of the same size will only differ in 1 bit, so:

    X xor S = Y
    and
    Y xor S = X

    I say offset since you have to start at location 0 for this to actually work right.

    Cheers,
    Tonalvoltage

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Operating System
    By Houssen in forum C Programming
    Replies: 18
    Last Post: 04-22-2008, 12:51 PM
  2. File System Implementation
    By dodgeviper in forum C Programming
    Replies: 9
    Last Post: 11-16-2007, 01:04 PM
  3. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 07:56 PM
  4. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  5. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 07:12 AM