Thread: Help designing data structure

  1. #16
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    Quote Originally Posted by kotoko View Post
    Knowing this, do smart pointers make more sense? (Yes a database makes even more but I want to put that aside for now)
    It depends. If the actual object is guaranteed not to go out of scope*, a raw pointer is sufficient. Otherwise, use a smart pointer; managing memory directly (via new/delete) is *never* acceptable- violating RAII is the surest path to undefined behavior! Anyway, I'd recommend using std::tr1::shared_ptr or the like.

    *That can be trickier than it sounds. For example, if you store your objects in an std::vector, a pointer to one of it's elements could become invalidated once another object is added to the vector. On the other hand, an std::list would work fine. Point is, choose your data structure carefully, and be sure to RTFM.
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Quote Originally Posted by kotoko View Post
    @tabstop I think we might be having what we call in Portuguese a deaf men conversation. What I'm saying is I do not want to duplicate. What I understand from your suggestion is that I will have to duplicate. What I'm asking is is this really what you are suggesting (to have duplicate).
    I have said, and will continue to say, exactly the opposite. My suggestions have been built around not duplicating any objects. (Or, I suppose, at least are consistent with them -- you may have to consistently take the pointer option when a choice was presented.)
    Last edited by tabstop; 12-30-2010 at 07:54 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Packet Container Class
    By ChaoticXSinZ in forum C++ Programming
    Replies: 2
    Last Post: 11-01-2010, 01:07 AM
  2. pthread question how would I init this data structure?
    By mr_coffee in forum C Programming
    Replies: 2
    Last Post: 02-23-2009, 12:42 PM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 11:36 AM
  4. C diamonds and perls :)
    By Carlos in forum A Brief History of
    Replies: 7
    Last Post: 05-16-2003, 11:19 PM
  5. Dynamic Data Structure -- Which one is better?
    By Yin in forum C++ Programming
    Replies: 0
    Last Post: 04-11-2002, 12:38 AM
Website Security Test