[Qt-interest] How to clear QVector without releasing memory?
Atlant Schmidt
aschmidt at dekaresearch.com
Fri Jun 17 18:27:11 CEST 2011
Robert:
Well, if I'm reading this right, on initial construction, Qt just delivers
zeroed memory to you so that suggests one way you could reinitialize
an already-allocated QVector.
Depending on how much safety you're willing to dispense with, you
can probably memset() much less area than the full p->array data
area. On theother hand, if your data area is a multiple of some large
natural size (4, 8, 16, or 32 bytes) and especially if the data area is
itself naturally-aligned, memset() is usually a highly-optimized
routine so I would expect qMemSet() to also be highly-optimized.
Atlant
>From qvector.h:
template <typename T>
QVector<T>::QVector(int asize)
{
d = malloc(asize);
d->ref = 1;
d->alloc = d->size = asize;
d->sharable = true;
d->capacity = false;
if (QTypeInfo<T>::isComplex) {
T* b = p->array;
T* i = p->array + d->size;
while (i != b)
new (--i) T;
} else {
qMemSet(p->array, 0, asize * sizeof(T));
}
}
________________________________
From: qt-interest-bounces+aschmidt=dekaresearch.com at qt.nokia.com [mailto:qt-interest-bounces+aschmidt=dekaresearch.com at qt.nokia.com] On Behalf Of Schimkowitsch Robert
Sent: Friday, June 17, 2011 10:19
To: qt-interest at qt.nokia.com
Subject: [Qt-interest] How to clear QVector without releasing memory?
Hi,
I have a QVector that I want to re-use many times as a buffer. As the application is long-running on a low memory device, memory fragmentation might be an issue.
To keep this in check, I would like to reserve() the QVector once, with the maximum size I am going to need, and then re-use it without ever freeing up memory.
The only ways to clear all items from the vector I found will also deallocate memory.
What is the performace-optimal way to clear a QVector without deallocating memory?
Robert Schimkowitsch
________________________________
This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.
ANDRITZ HYDRO GmbH
Rechtsform/ Legal form: Gesellschaft mit beschrankter Haftung / Corporation
Firmensitz/ Registered seat: Wien
Firmenbuchgericht/ Court of registry: Handelsgericht Wien
Firmenbuchnummer/ Company registration: FN 61833 g
DVR: 0605077
UID-Nr.: ATU14756806
Thank You.
________________________________
Click here<https://www.mailcontrol.com/sr/DrQKr8NeseDTndxI!oX7UlFqrXJaieUT+UC0lrCks8YOmy5n2oX8N8IhWDO+yjG3FTRhtP!ntKGBj3G9C26e4g==> to report this email as spam.
________________________________
This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.
Thank you.
Please consider the environment before printing this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110617/1fe7e286/attachment.html
More information about the Qt-interest-old
mailing list