This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: limit for # of items created with "new" ?


From: Hans Horn [mailto:hannes@2horns.com]
> 
> // an element of a linked list
> typedef struct node {
>   node (int _v, node* _n) : v(_v), next(_n) {}
>   int   v;
>   node* next;
> };

I'm surprised that compiled; the typedef shouldn't be there.

> int main (int argc, char** argv) {
>   // allocate descriptions of points
>   char** points = new char*[NUM_POINTS]; assert(points);

The assert is superfluous; new is guaranteed never to return null.

>   for (int i = 0; i < NUM_POINTS; i++) {
>     points[i] = new char[2800]; assert(points[i]);
>   }

You're allocating 2800 bytes for each of 85000 entries; that's 238
megabytes so far. You said earlier that it failed when you tried it
with 1.6 million objects (which I take to mean that was the value of
NUM_POINTS). I'm not surprised; that would have tried to allocate
four and a half gigabytes of memory!

> [ lots of code snipped ]

I also recommend that you start learning about the standard library;
you're reinventing a lot of wheels here.

-- 
Ross Smith ...................... Pharos Systems, Auckland, New Zealand

"C++ is to programming as sex is to reproduction. Better ways might
technically exist but they're not nearly as much fun." - Nikolai Irgens
 

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]