Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey there,

I'm not a profesional programmer and while creating a small project
I actualy wondered, how can I create alot of objects without taking to much memory of my PC.

Like e.g. if you remembered the games Age of empires(AOE) and Cossacks
in AOE you could only make about 120 units, but in cossacks you could create infinity amount of units (figure of speech :-) )

How were they able to do that?
How is this technique called?

Thanks
Posted
Comments
Legor 22-Oct-12 9:35am    
This can't be answered in general. Depending on the plattform and programming language there are many different ways of how one can achieve a proper memory management. It is dependent on the available hardware ressources e.g. RAM) as well as how these ressources are used.

There is no such "technique" - it's a case of different approaches. Why one game has a limit of 120 units, and the other no apparent limit, is (probably, I've never seen the code for either) more to do with how the objects are handled than how much memory they take up.
For example, if each unit is considered individually (and has to make individual decisions as to where it goes, what it does, if it lives, dies or runs away) that that will take a lot more processing power than if a bunch of them are considered as a group. But the first may be more realistic as far as human behaviour is concerned.

Sorry, but there is no simple answer "use this, and you can create as many objects as you need" - it depends on teh system as a hwhole, and the data you store, and how you need to store it.
 
Share this answer
 
The Flyweight Pattern might be able to help you in this: Flyweight Pattern[^].

Cheers,

— Manfred
 
Share this answer
 
v2
Brother see there is always a liitation of memory in every device there are 2 concepts
1> ststic memory allocation
2> dynamic memory allocation
the variable you are using How You give size of that it depends on that how much memory it will consume...in static memory allocation
and linklist is example of dynamic memory allocation
see this link
http://www.geekinterview.com/question_details/3443
and
http://www.megasolutions.net/cSharp/How-can-I-reduce-the-memory-consumption_-58887.aspx
and other factors of programming also affect the memory consumption
like unwanted loop iterations , use of unwanted variables, one statment logic done in 3 to 4 statements etc you can find more on Google
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900