Hi all.
I have a virtual "world" with different objects which are "born" and
which "die" sometimes. This means I have a variable amount of objects in
this world which I need to store in some structure.
Sounds like a perfectly good job for vectors (STL).
Another method would be to create a pre-defined, empty array. Now if an
object is born, the next free slot in this array is searched and the new
object is stored at that position. When an object dies, the
corresponding slot is simply "freed" again.
Now my question:
Which of this methods (STL, array) will be faster if my world has a huge
number of objects (5000-10000)?
Maybe any other ideas?
Regards,
Jan 7 3001
In article <MP************ ************@ne ws.t-online.com>,
Jan Krumsiek <ja**********@g mx.de> wrote: Hi all.
I have a virtual "world" with different objects which are "born" and which "die" sometimes. This means I have a variable amount of objects in this world which I need to store in some structure.
Sounds like a perfectly good job for vectors (STL).
If most of your insertions and deletions are at the end of the
sequence, then yes, vector sounds reasonable. However, if it is likely
that objects anywhere in your "world" can "die", (i.e. if you will
frequently be removing items from the middle of the sequence), another
container may be better (like list or set).
Clark Cox <cl*******@mac. com> writes: In article <MP************ ************@ne ws.t-online.com>, Jan Krumsiek <ja**********@g mx.de> wrote:
Hi all.
I have a virtual "world" with different objects which are "born" and which "die" sometimes. This means I have a variable amount of objects in this world which I need to store in some structure.
Sounds like a perfectly good job for vectors (STL).
If most of your insertions and deletions are at the end of the sequence, then yes, vector sounds reasonable. However, if it is likely that objects anywhere in your "world" can "die", (i.e. if you will frequently be removing items from the middle of the sequence), another container may be better (like list or set).
You may also want to look into using some sort of small object
allocator routine, depending on the size of these objects, since they
are so many.
"Jan Krumsiek" <ja**********@g mx.de> wrote in message
news:MP******** *************** *@news.t-online.com... Hi all.
I have a virtual "world" with different objects which are "born" and which "die" sometimes. This means I have a variable amount of objects in this world which I need to store in some structure.
Sounds like a perfectly good job for vectors (STL).
Another method would be to create a pre-defined, empty array. Now if an object is born, the next free slot in this array is searched and the new object is stored at that position. When an object dies, the corresponding slot is simply "freed" again.
Now my question:
Which of this methods (STL, array) will be faster if my world has a huge number of objects (5000-10000)?
I would expect them to be almost exactly the same. You should choose on the
basis of which results in simpler code. Maybe any other ideas?
Actaully sounds much more like a task for STL list or map depending on your
requirements. I would expect either of those to be faster than vector or
array.
The most important thing is that, whatever data structure you choose, you
create a class that hides the details of that representation from the rest
of your program. That way you can change the representation in the future
without affecting the rest of the program. This seems especally imoprtant in
this case because you are unsure of what is the best, and you seem
interested in expereimenting to find out.
john
John Harrison wrote: The most important thing is that, whatever data structure you choose, you create a class that hides the details of that representation from the rest of your program. That way you can change the representation in the future without affecting the rest of the program. This seems especally imoprtant in this case because you are unsure of what is the best, and you seem interested in expereimenting to find out.
Yes, i get what you mean. I will create some CWorld class with "add",
"remove" and "getobject" methods.
Jan
Clark Cox wrote: If most of your insertions and deletions are at the end of the sequence, then yes, vector sounds reasonable. However, if it is likely that objects anywhere in your "world" can "die", (i.e. if you will frequently be removing items from the middle of the sequence), another container may be better (like list or set).
Yes, actually objects can spawn and be removed all the time during the
main loop. Why is list or set better then? What are the differences?
Regards,
Jan
Billy O'Connor wrote: You may also want to look into using some sort of small object allocator routine, depending on the size of these objects, since they are so many.
Thanks for the tip, but what do you mean with "small object allocater
routine"? Wouldn't that be something like the array I described in my
original posting?
Regards,
Jan
Jan Krumsiek wrote: Clark Cox wrote:
If most of your insertions and deletions are at the end of the sequence, then yes, vector sounds reasonable. However, if it is likely that objects anywhere in your "world" can "die", (i.e. if you will frequently be removing items from the middle of the sequence), another container may be better (like list or set).
Yes, actually objects can spawn and be removed all the time during the main loop. Why is list or set better then? What are the differences?
Regards, Jan
because removing from the middle of a vector involves copying everything
after the removal point. It's O(n), whereas removing from a list is
O(1), and (i think) a set is O(log(n)) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Vasileios Zografos |
last post by:
Hello,
I have a function that generates some values (e.g. vertices in 2d space)
the number of which I dont know. So, it could generate 20 vertices, 100
vertices, or even 1 vertex.
void generateVals()
{
.....
//generate some values
|
by: Scott Lyons |
last post by:
Hey all,
Can someone help me figure out how to pass a dynamic array into a function?
Its been giving me some trouble, and my textbook of course doesnt cover the
issue. Its probably something simple, but its just not popping into my mind
at the moment.
My little snippet of code is below. Basically, the studentID array is
dynamic so it will fit any length of a Student's Name. What I'm trying to
do is place this chunk of code into a...
|
by: meyousikmann |
last post by:
I am having a little trouble with dynamic memory allocation. I am trying to
read a text file and put the contents into a dynamic array. I know I can
use vectors to make this easier, but it has to be done using dynamic arrays.
I don't know the size of the text file ahead of time, though, so I created a
class that includes a method to resize the array. Here is that class:
class Data
{
public:
Data(int initialsize);
|
by: Peter B. Steiger |
last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C
is a simple word game that involves stringing together random lists of
words. In the Pascal version the whole array was static; if the input
file contained more than entries, tough.
This time I want to do it right - use a dynamic array that increases in
size with each word read from the file. A few test programs that make use
of **List and realloc( List, blah...
|
by: Materialised |
last post by:
Hi Everyone,
I apologise if this is covered in the FAQ, I did look, but nothing
actually stood out to me as being relative to my subject.
I want to create a 2 dimensional array, a 'array of strings'. I already
know that no individual string will be longer than 50 characters. I just
don't know before run time how many elements of the array will be needed.
I have heard it is possible to dynamically allocate memory for a 2
| |
by: lemonade |
last post by:
Hello!
Can someone explain to me the difference between dynamic
array of pointers vs dynamic array of objects by giving a
real life example. Following is the code that I am using
for dynamic array of objects. I am skipping initialization
and other member functions.
class Inventory {
Item *itemList;
int idx, count, size;
|
by: assgar |
last post by:
Hi
Developemnt on win2003 server. Final server will be linux
Apache,Mysql and PHP is being used.
I use 2 scripts(form and process).
The form displays multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply.
Each dynamically created row will return 3 values fee1_choice, fee1_unit and fee1_money.
Note The above informaton is...
|
by: pjr |
last post by:
Using VS2005, I dynamically create an event delegate. Code follows question.
My method gets the event's parameters and passes them onto a common event handler. My delegate gets called when expected and in turn, calls my common event handler. However, once in the common event handler code, the "this pointer" is wrong and hence I can't access other class properties and methods.
Even if I invoke the dynamic method directly, the "this pointer" is...
|
by: C C++ C++ |
last post by:
Hi all, got this interview question please respond.
How can you quickly find the number of elements stored in a a) static
array b) dynamic array ?
Rgrds
MA
|
by: kwikius |
last post by:
Does anyone know what a C99 dynamic array is, and if it will be
useable in C++?
regards
Andy Little
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |