Linked List w/o "new" ?

This is a discussion on Linked List w/o "new" ? within the C++ Programming forums, part of the General Programming Boards category; I have a program where I have an array of memory called hypomem[10000]. I have implemented a cpu simulator which ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    74

    Linked List w/o "new" ?

    I have a program where I have an array of memory called hypomem[10000]. I have implemented a cpu simulator which loads a program into hypomem, then executes the program (which is written in machine language) by doing operations such as add, subtract, etc. I am now writing simulator functions for an operating system so I can load more than one program and have a scheduler run the programs according to priority. What i need to do is use linked lists to allocate portions of the hypomem for different things. I cannot use the "new" since that will not allocate it in the hypomem, it will allocate it in the machines main memory. Does anyone know how I would go about this? Are there any programs out there that someone can post that will show me how this works? Any help is appreciated.

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904

    Re: Linked List w/o "new" ?

    wow, that's taking virtual computer to a whole new level what i'd suggest is making your own function that will return a "pointer" to a spot in your hypomem. for example:

    Code:
    unsigned int createHypoDat(unsigned int size)
    {
    	do some stuff to find the next closest empty "block" of hypomem
    	return <index to the beginning of the block>
    }
    That seems like the best way to do it to me, i'm not sure how you'd efficiently make sure that you weren't writing over other blocks and things, but that's a good place to start i guess

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Why do you need to use the static array anyways? Can't you dyamically allocate one (or more) based on how much memory you need?

    If you still want to allocate hypomem... basically what allocation is (from what I know) is giving you a pointer to the section of memory, and marking that area off as "reserved" so that nothing else will modify the data. You could try setting up a linked list or vector of 'fenced-off' areas or something, and add to it when you 'new' and delete from it when you 'delete'. I haven't tried anything like this before, but that's all I can think of.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    74
    Thanks guys. I'm going to give jverkoey's suggestion a try. It seems to make sense if I can get it to work!!

  5. #5
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    probably a mergence of mine and hunter2's suggestion would be a good thing to do, as hunter2's would make sure that you aren't returning a pointer to a block of memory that overlaps another one's memory

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    If the memory allocated is a class, you could overload the new operator and manually take memory from that array.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 11:03 AM
  2. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 09:04 PM
  3. Replies: 5
    Last Post: 11-04-2006, 06:39 PM
  4. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 11:01 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21