Thread: Objects or pointers in STL containers?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459

    Objects or pointers in STL containers?

    G'day,

    Doing a little input manager for a project of mine. Basically I have an input event (InputEvent), which is a simple, small class. And then a user-defined function which takes an std::queue<InputEvent>.

    The user-defined function is called about 100 times a second. With say a max of 10 input events per-call. Is it wise to be storing InputEvent objects in the queue or should I be storing pointers?

    Basically I don't want to make the user free the InputEvent pointers themselves.

    Secondly, should I specifically make my InputEvent copyable (ie override operator=)?

    In short I have,

    My library
    Code:
    // ...
    
    std::queue<InputEvent> events_;
    
    // ... add the events to the queue
    
    events_.push(InputEvent(x, y));
    events_.push(InputEvent(x, y));
    events_.push(InputEvent(x, y));
    
    client->frame(&events_);
    
    // ...
    User's code
    Code:
    void frame(std::queue<InputEvent> * events)
    {
        // the InputEvents are removed from the queue
    }
    Thanks!
    Zac
    Last edited by zacs7; 06-21-2009 at 07:47 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "Big" Objects and STL Containers
    By dudeomanodude in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2008, 12:13 AM
  2. pointers in arrays... Declaring objects in a loop.
    By Guest852 in forum C++ Programming
    Replies: 10
    Last Post: 04-05-2005, 06:57 AM
  3. stl - searching for elements in containers
    By Raven Arkadon in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2005, 11:10 AM
  4. array of pointers to objects
    By xion in forum C++ Programming
    Replies: 6
    Last Post: 02-07-2005, 07:14 PM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM