This is the mail archive of the 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" ?


That looks like over 80 megabytes just for the dynamically allocated "node" instances:

85000 * 30 * (8 + 8) * 2

If I understand correctly, all Cygwin app memory comes out of a single pool (hence the Cygwin heap size registry entry), so a proper accounting of available memory must take the other concurrently executing Cygwin applications into account.

Randall Schulz
Mountain View, CA USA

At 18:00 2002-09-24, Hans Horn wrote:

"Igor Pechtchanski" <> wrote in message">
> Don't forget the object headers - depending on which options you use, they
> can be 8 bytes per object. It would really help to see the source of the
> crashing program, at least the snippet with the allocation and dereferencing.

Are there options that cost less (in terms of object headers) that the defaults?

Allrighty, here's the essence of what's going on:

// compiled with : gcc -O2 tst.cpp -o tst -lstdc++
// gcc version: 3.2

#define NUM_POINTS 85000
#define NON_ZERO 30

// problem: have a collection of NUM_POINTS points,
// - each point has attached ca 2800 byte descriptive info
// - each point has two kinds (left and right) of neighbors.
// actual neighborhood of all points is given by a very sparse
// having on average only NON_ZERO non-zero elements per row/column.

#include <stdio.h>
#include <iostream.h>
#include <assert.h>

// an element of a linked list
typedef struct node {
node (int _v, node* _n) : v(_v), next(_n) {}
int v;
node* next;

int main (int argc, char** argv) {
// allocate descriptions of points
char** points = new char*[NUM_POINTS]; assert(points);
for (int i = 0; i < NUM_POINTS; i++) {
points[i] = new char[2800]; assert(points[i]);
cout << "inited points[]" << endl;

// represent neighborhood for each point via linked lists :
node** adjl = new node*[NUM_POINTS]; assert(adjl); // neighbors to the left
node** adjr = new node*[NUM_POINTS]; assert(adjr); // neighbors to the right
for (int i = 0; i < NUM_POINTS; i++) { adjl[i] = adjr[i] = NULL; }
for (int i = 0; i < NUM_POINTS; i++) {
for (int j = 0; j < NON_ZERO; j++) {
adjl[i] = new node(j, adjl[i]); assert(adjl[i]);
adjr[i] = new node(j, adjr[i]); assert(adjr[i]);
cout << "i " << i << ": total " << (i+1) * 2 * NON_ZERO << endl;
// last output: "i 29950: total 1797060"
cout << "inited adjl,r[]" << endl;

// process points[] and adjl,r[]

// clean-up

return 0;


Unsubscribe info:
Bug reporting:

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