"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!
QList is a container class ... that means that it manages the memory for you so you don't have to worry about it. It's underlying data-structure is a variant of a deque with some special modifications so your understanding of indexing into the list is not correct. But either way, these are details that are abstracted away by the interface, and you don't need to worry about them.
You simply use the given class methods like operator or at() to obtain a reference to an object at a given index, and other functions like push_back() or insert() to copy objects into the container. So you can simply make a QList instance on the stack (as long as it doesn't go out-of-scope while it's needed), and copy objects into it. The underlying data-structure will properly allocate the memory needed dynamically to store the objects, and at the time of destruction of the QList object, it will deallocate the memory used to store the objects it "owns".
Up vote 1 down vote favorite share g+ share fb share tw.
I don't want that. Secondly, if I pick the 3rd solution, how would this look in memory when I access the individual objects? And could I create pointers to them (they are afterall on the heap)?
Then we come to my other issue. This list will be past around like a fork at a diner and at some point I would like to create sublists that doesn't hold any data, only references/pointers to some of the objects in the list(for example object 0 to 250). I will then throw these lists into different threads that will have to have a ref to the object to be able to edit them (read: not a hard copy).
Also, could someone explain exactly what happens on the heap when you create a list like this: QList* list = new QList(); Would it be like in c where you just create a pointer to the offset where that object will be located? *(list + sizeof(FileInfoWrapper) * 10) c++ c qt pointers link|improve this question asked Feb 22 at 3:40chikuba430111 74% accept rate.
QList is a container class ... that means that it manages the memory for you so you don't have to worry about it. It's underlying data-structure is a variant of a deque with some special modifications, so your understanding of indexing into the list is not correct. But either way, these are details that are abstracted away by the interface, and you don't need to worry about them.
You simply use the given class methods like operator or at() to obtain a reference to an object at a given index, and other functions like push_back() or insert() to copy objects into the container. So you can simply make a QList instance on the stack (as long as it doesn't go out-of-scope while it's needed), and copy objects into it. The underlying data-structure will properly allocate the memory needed dynamically to store the objects, and at the time of destruction of the QList object, it will deallocate the memory used to store the objects it "owns".
Think about QList as you would think of a STL container like std::vector or std::list ... again, the underlying data-structure for QList is not the same as these STL containers, but the point is that you can allocate the data-structure on the stack like you would any other class, and it contains all the private data-members and information necessary to manage the memory on the heap. Allocating the QList on the heap through a call to new doesn't gain you anything in that regard ... there are already pointers, etc. inside the data-structure allocating and managing the memory of the contained objects for you. Finally, don't worry about data-fragmentation.
The point of a good container class is to properly allocate memory to avoid memory fragmentation issues from allocating and reallocating memory too often. Additionally, allocating memory takes time, so if a container class were to constantly need to call new, that would really hurt it's performance. While allocating memory on every insertion may be a necessity for node-based containers like linked-lists and trees, hash-tables, dynamic-arrays, and other block-type data-structures are much more efficient at utilizing the memory they allocate to minimize these allocation calls.
I might just be extremely tired, but I'm not sure if you answered my second question about how I should pass chunks of the original list as referense to different threads. I would like to do QListRef(list. At(start), list.
At(end)) and then pass this as a list so I easly can go through it with "foreach" for example. – chikuba Feb 22 at 4:26 Yeah, I don't see why you couldn't do that ... the thing to keep in mind is that if you plan on modifying the data-structure after you've passed it to the threads (i.e. , adding more objects), then beware of invalidating the location of objects (i.e.
, an underlying memory reallocation could move the contents of the stored objects somewhere else, and then your threads referencing those objects are referencing nothing). If you need a data-structure that won't change as you add or subtract objects, you may want to look into QLinkedList. – Jason Feb 22 at 4:32 Wait what?
My plan is to pass it as reference to the class and then use QList::at() to work with one of the objects. Do you mean that if I added an object in the list simultaneously as I work with that reference, I might get problems? – chikuba Feb 22 at 6:06 Yes.
It's kind of a separate question, but some data containers guarantee that as one thread adds objects to the container, it does not relocate memory for any of the other objects in the container. I'm not sure if QList makes this guarantee. A QLinkedList though would make that guarantee.
– Jason Feb 22 at 11:19.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.