Hallo,
ich hab bei einem Programm bei mir festgestellt, daß das "deleten" von
Feldern erheblich länger dauert, als das Anlegen von Feldern. p. Bei
einem Programm von mir werden oft große Datenfelder unterschiedlich er
Größe angelegt und wieder gelöscht. Daher ist dieser Umstand sehr ungünstig.
Ist das Normal, daß der Unterschied bei Faktor 10-20 liegt? Oder begehe
ich hier an irgendeiner Stelle einen grundlegenden Fehler!?
Danke für die Hilfe.
Gruß Axel
code:
QTime t;
t.start();
double** data = new double*[1300];
for (int i=0;i<1300;i++) data[i] = new double[1300];
cout << "needed to create: " << t.elapsed() << " mseconds"<<endl ;
t.start();
for (int j=0;j<1300;j++) delete [] data[j];
delete [] data;
cout << "needed to delete: " << t.elapsed() << " mseconds"<<endl ;
Programm Ausgabe (auf AthloxXP1800, kompiliert mit MS-VC6 - release,
optimiert auf Geschwindigkeit ):
needed to create: 31 mseconds
needed to delete: 484 mseconds
Jul 23 '05
13 1749
Torsten Mueller schrieb: Axel Panning <ax**@harnackst rasse.de> schrieb:
So the question in english again:
Is it normal that the creation of a datafield using the "new" operator is approximately 10 to 20 times faster than deleting the same? Am I mistaken any way in the code below?
Deletion is not easy. A heap object is normally located in a larger block ob memory. This larger block contains more than one object. If a single object is deleted the heap management must look if there are still other objects in the same block or not to free the entire block if possible. This happens in every single delete and this takes time. The new is much easier.
You have large arrays with elements of the same data type. You should try to make one large array with a two dimensional shape. Of course you must compute the indexes of rows and columns yourself. But this will be much faster than the multiple news and deletes.
T.M.
tried it.
-> snip
double* dataEasy = new double[arr_size*arr_si ze];
double** dataEasyAccess = new double*[arr_size];
for (int k=0;k<arr_size; k++) dataEasyAccess[k] = dataEasy + k*arr_size;
-> snap
having the same datastructure afterwards in 'dataEasyAccess '. Else i had
to change a lot of code ;).
The timings are very ok now. Thanks for the idea, but i wonder why i
dont have the results like the guys in the other postings with my old code.
Thanks a lot.
John Carson schrieb: "Axel Panning" <ax**@harnackst rasse.de> wrote in message news:db******** **@online.de
Oops. forgot this is an english newsgroup .
So the question in english again:
Is it normal that the creation of a datafield using the "new" operator is approximately 10 to 20 times faster than deleting the same? Am I mistaken any way in the code below?
Thanks
code: QTime t;
t.start(); double** data = new double*[1300]; for (int i=0;i<1300;i++) data[i] = new double[1300]; cout << "needed to create: " << t.elapsed() << " mseconds"<<endl ;
t.start(); for (int j=0;j<1300;j++) delete [] data[j]; delete [] data; cout << "needed to delete: " << t.elapsed() << " mseconds"<<endl ;
Output (on AthlonXP1800, compiled with MS-VC6 - release, speed-optimized): needed to create: 31 mseconds needed to delete: 484 mseconds
Running VC++7.1 on Windows XP, Pentium M 1.5Ghz, 512Mb memory, I had to increase the dimensions by a factor of 10 to get something clearly non-zero. I then find that the create takes at least 3 times as long as the delete and often much longer, e.g.,
needed to create: 90 mseconds needed to delete: 20 mseconds
factor 10??
13000*^2=169.00 0.000. multiplied by 8(double) > 1Gig. This sould cause
your pc to allocate this in temporary file. You seem to have a fast
harddisk ;) class QTime { int start_, finish_; public: void start() { start_ = clock(); } int elapsed() { finish_ = clock(); return (finish_-start_); } };
const int K = 13000;
int main() { QTime t;
t.start(); double** data = new double*[K]; for (int i=0;i<K;i++) data[i] = new double[K]; cout << "needed to create: " << t.elapsed() << " mseconds"<<endl ;
t.start(); for (int j=0;j<K;j++) delete [] data[j]; delete [] data; cout << "needed to delete: " << t.elapsed() << " mseconds"<<endl ; }
This is confusing to me. Only get fast results sing this code...
-> snip
double* dataEasy = new double[arr_size*arr_si ze];
double** dataEasyAccess = new double*[arr_size];
for (int k=0;k<arr_size; k++) dataEasyAccess[k] = dataEasy + k*arr_size;
-> snap
On Wed, 13 Jul 2005 13:21:17 +0200, Axel Panning <ax**@harnackst rasse.de>
wrote: I don't know that class QTime, but I have seen similar classes needed to No it's working fine that way. It is from the Qt-Frameword (www.trolltech.com). Is there a standard-c function to get msec's? I never watched out befor for it. Always used the QTime class. My first short search didnt find any.
clock() in <ctime>
and divide the result by CLOCKS_PER_SEC or CLK_TCK to get seconds.
resolution is not better than 1 ms.
"Axel Panning" <ax**@harnackst rasse.de> wrote in message
news:db******** **@online.de This is confusing to me. Only get fast results sing this code...
-> snip double* dataEasy = new double[arr_size*arr_si ze]; double** dataEasyAccess = new double*[arr_size]; for (int k=0;k<arr_size; k++) dataEasyAccess[k] = dataEasy + k*arr_size;
I don't know what explains it. I tried using VC++ 6.0 on both NT4 and XP and
I still get create taking a lot more time than delete.
--
John Carson This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dave |
last post by:
Hello all,
In the code below, I see the following output:
base::operator new(size_t, int)
base::base()
base::~base()
base::operator delete(void *)
In the case of an exception being thrown during construction, a form of
|
by: Nimmi Srivastav |
last post by:
There's a rather nondescript book called "Using Borland C++" by Lee
and Mark Atkinson (Que Corporation) which presents an excellent
discussion of overloaded new and delete operators. In fact there are
quite a few things that I learned that I did not know before. For
example, while I knew that the new and delete operators can be
overloaded for classes, I did not know that that the global new and
delete operators can also be overloaded. ...
|
by: Nimmi Srivastav |
last post by:
There's a rather nondescript book called "Using Borland C++" by Lee
and Mark Atkinson (Que Corporation) which presents an excellent
discussion of overloaded new and delete operators.
I am presenting below a summary of what I have gathered. I would
appreciate if someone could point out to something that is specific to
Borland C++ and is not supported by the ANSI standard. I am also
concerned that some of the information may be outdated...
|
by: Ioannis Vranos |
last post by:
When we use the standard placement new operator provided in <new>, and
not a definition of owr own, isn't a call to placement delete enough?
Consider the code:
#include <new>
|
by: silver360 |
last post by:
Hello,
I'm trying to create a basic Heap manager and i have some question
about new/delete overloading.
The following code give me this output :
>> $./heap
>> registered : 0x804d098
>> 0x804d008 _Delete unknown block
>> registered : 0x804d138
>> 0x804d008 _Delete unknown block
>> 0x804d098 _Delete ok
| |
by: junw2000 |
last post by:
I use the code below to study delete and destructor.
#include <iostream>
using namespace std;
struct A {
virtual ~A() { cout << "~A()" << endl; }; //LINE1
void operator delete(void* p) {
cout << "A::operator delete" << endl;
|
by: Lighter |
last post by:
Big Problem! How to overload operator delete?
According to C++ standard, "A deallocation function can have more than
one parameter."(see 3.7.3.2); however, I don't know how to use an
overloaded delete operator. Let me use an example to illustrate this:
/********************************************************/
#include <new>
#include <iostream>
|
by: yufufi |
last post by:
Hello,
How does delete know how much memory to deallocate from the given
pointer? AFAIK this informations is put there by new. new puts the
size of the allocated memory before the just before the beginning of the
array. But I couldn't find this information by looking at the memory.
(Via VS2005 - C++)
My second questions is, if there is a mechanism to know how much memory
is allocated for the array, why don't we use it for things like...
|
by: jeffjohnson_alpha |
last post by:
We all know that a new-expression,
foo* a = new foo() ;
allocates memory for a single foo then calls foo::foo(). And we know
that
void* p = ::operator new(sizeof(foo)) ;
allocates a sizeof(foo)-sized buffer but does NOT call foo::foo().
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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
| |