Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualKing Mir

Posted 20 February 2013 - 10:12 AM

Regarding references, they are never stored anywhere, only retrieved for modification through the State objects by the as() method, and it's always just that one line ( state.as() = 10; )

You still have a bug. If two object are ever retrieved at the same time, and the second causes some vector to resize, the first reference to the first object will become invalid. You need to use a std::deque. Or a std::list, but deque is almost always faster.

 



The State isn't a template class because i want to be able to store different types of data in the same container. Such as:



State intState = 10; //calls the templated copy ctor

State stringState = std::string("some text");

std::vector states;

states.push_back(intState);

states.push_back(stringState);



The
container can actually be any STL container, which stores the State
objects by value (and they keep only a handle to the actual data).

Reason
why i went for State at all is because if i have 2 entities, with each
of them containing say 5 states (all of which are different types for
example), and one of the entities gets deleted, the States themselves
are automatically destroyed too, and the data they were pointing to is
no longer used, and can be overwritten when a new state of that type is
created (it just overwrites the previously used location).

Gotcha. You're using _storeRepo->getDataStore<T>() to check if the stored type matches the accessed or assinged type, by _storeRepo->getDataStore<T>() is an expensive operation, involving a hashmap search. You can find a less expensive way to do this check.

#1King Mir

Posted 20 February 2013 - 10:03 AM

Regarding references, they are never stored anywhere, only retrieved for modification through the State objects by the as() method, and it's always just that one line ( state.as() = 10; )

You still have a bug. If two object are ever retrieved at the same time, and the second causes some vector to resize, the first reference to the first object will become invalid. You need to use a std::deque. Or a std::list, but deque is almost always faster.

PARTNERS