RE: [Dev-C++] Optimized memory allocation
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@em...> - 2003-06-20 03:20:52
|
Bug fix: =20 -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Ioannis Vranos Sent: Friday, June 20, 2003 5:48 AM To: 'C++' Subject: RE: [Dev-C++] Optimized memory allocation =3D=3D> new whatever[SIZE] should be equivalent to malloc(SIZE*sizeof(whatever)) in terms of speed, where whatever is a = POD type. =20 But better use an std::vector: =20 =20 #include <vector> =20 // ... =20 using std::vector; =20 // ... =20 vector<class_type> array(48); =20 // ... array[0]=3D ... =20 =20 =20 =20 =20 Ioannis Vranos * Programming pages: <http://www.noicys.freeurl.com/> http://www.noicys.freeurl.com * Alternative URL 1: <http://run.to/noicys> http://run.to/noicys * Alternative URL 2: <http://www.noicys.cjb.net/> = http://www.noicys.cjb.net =20 =20 =20 -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Shane = Bryldt Sent: Friday, June 20, 2003 3:39 AM To: C++ Subject: [Dev-C++] Optimized memory allocation Hello, =20 I have recently been attempting to find ways to speed up the process = of loading 48k records from a MySQL SELECT statement, which has a 32 char primary key. One of the more intensive processes involved is calling = "new" to create a new object 48k times. In standard C, I would = malloc(RowCount * sizeof(class_type)), and using pointer math, simply iterate whenever I needed a new structure. With C++, a call to new is required for construction purposes. Is there an optimized method wherein I can = allocate a dynamic number to be preallocated more efficiently all at once in one call? I have considered using "new class_type[RowCount]()" to allocate an array (haven't tried to see if that would actually work), but I was wondering if there was a more efficient means to preallocate objects. =20 Thanks, -Shane |