When I am using the Object pool design pattern, and allowing the pool to grow, by creating new objects when they are required but not available in the pool, and placing them in the pool after they have been used, can it eventually cause memory shortage, or some kind of an out of memory exception/error?
It looks very reasonable that after some time it will happen, because the pool grows, and the object within it don’t get deleted.
Go to Source
I’m writing in C++, but this problem applies to any language without GC and even to languages with a GC as well.
I have a structure in memory in which I create/add objects. The structure takes ownership of those objects. I should never need to use an object after it’s removed from the structure.
When I first implemented this data structure, it seemed natural to use an ID/key/name/handle for the objects stored in it. I’m using it like this:
id1 = structure.addObj(new Square());
id2 = structure.addObj(new Square());
id3 = structure.addObj(new Circle());
obj3 = structure.getObj(id3);
obj3.addFriend( id1 );
obj3.addFriend( id2 );
idMax = structure.findObjWithMostFriends();
objMax = structure.getObj(idMax);
After using it for a while, I’m thinking that it would be better to forget about the IDs and always use references to the objects instead. This way I wouldn’t need to pass a reference to the structure around every time.
I’m thinking about refactoring everything to only use references but I’m afraid of regretting it. I’d like to know more about what are the pros and cons of using IDs to decide whether I should proceed.
The objects are allocated on the heap and their address never changes.
The structure deallocates those objects when they’re removed (they could be released to the caller instead, but I don’t need this at the moment).
I’m not supposed to ever use objects that don’t belong to the structure. If my program is correct, I should never end up with a dangling ID or pointer. But it could happen if the program has bugs.
What are your experiences switching from IDs to references for similar problems? Which solution should I use?
Go to Source
I am trying to create a system, which has multiple queries for different kinds of reports. My plan is to queries in the database tag them report A, report B. Obvisouly SQL query will have some placeholders to pass paramterers.
I am trying reduce my coding work. So that i’ll keep adding queries in the database without touching the code.
i have explored diffrent django tool, but i haven’y found any suitable tool.
Any guidence will be apperictaed.
Go to Source
I am working on some project to learn how to make bigger and better software (multiplayer game) and I found a problem about having in my code a design pattern Command Pattern and anti-pattern God Object. Often I do end up win the latter one and I know that Fascades are okay, but my understanding of something being right and wrong in OOP is very blurry.
I’ve implemented the Command Pattern. Shortly, my command:
public interface IGameCommand : ICommand
bool Execute(Game game);
And an executor
public interface IExecutor<TState, TCommand>
void Execute(TCommand command);
Let’s say that I have a command that does a lot: modifies some data, plays sound etc.
So, in my case, this should look like this:
public class MagicSpell: IGameCommand
int x; int y; int damage; string soundClipName; string effectName;
bool Execute(Game game)
As you can see, this forces my Game class to become a God object… or doesn’t it? Since my Game class contains specialized classes that do their thing I am fulfilling the Single responsibility principle. I have some bad experience with ending up with a God Object, but is my solution viable and acceptable with OOP?
Or maybe is something wrong with my Command Pattern implementation and
Maybe making some specialized commands would help?
Go to Source