www.digitalmars.com         C & C++   DMDScript  

D - Out of memory?

reply Paul Runde <prunde consolidated.net> writes:
I've tried different variations of this:

class foo
{
    int   x;
    int   x1;
    int   x2;
    int   x3;
}

foo[] fooa;

int main(char[][] args)
{
    //fooa.length = 245760;
    while(1)
    {
       try fooa ~= new foo();
       catch
       {
          printf("Allocated %d instances of foo.\n", fooa.length);
          break;
       }
    }

    return 0;
}

This one creates 15360 instances of foo whether on a Win95 machine with 
128MB or on a WinME with 256MB.  I searched the docs and could not find 
anything.  Also, setting the length of the array to anything over 245760 
causes an Access Violation error.

What am I missing?

Thanks.
Jan 23 2004
next sibling parent reply J C Calvarese <jcc7 cox.net> writes:
Paul Runde wrote:

 I've tried different variations of this:
 
 class foo
 {
    int   x;
    int   x1;
    int   x2;
    int   x3;
 }
 
 foo[] fooa;
 
 int main(char[][] args)
 {
    //fooa.length = 245760;
    while(1)
    {
       try fooa ~= new foo();
       catch
       {
          printf("Allocated %d instances of foo.\n", fooa.length);
          break;
       }
    }
 
    return 0;
 }
 
 This one creates 15360 instances of foo whether on a Win95 machine with 
 128MB or on a WinME with 256MB.  I searched the docs and could not find 
 anything.  Also, setting the length of the array to anything over 245760 
 causes an Access Violation error.
 
 What am I missing?
 
 Thanks.
I don't think this is a limitation of D. It may be a limitation of Win9X. It probably also depends on the computer's available memory since each computer has a finite amount of RAM (even when you consider paging files). I have 128MB of RAM and I was running several programs at the same time. (I'm running WinXP Home.) This is what I got: Allocated 1411072 instances of foo. And I also got some friendly message boxes popping up telling me I was low on memory. And icons started disappearing. -- Justin http://jcc_7.tripod.com/d/
Jan 23 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
J C Calvarese wrote:

 Paul Runde wrote:

 I've tried different variations of this:

 class foo
 {
    int   x;
    int   x1;
    int   x2;
    int   x3;
 }

 foo[] fooa;

 int main(char[][] args)
 {
    //fooa.length = 245760;
    while(1)
    {
       try fooa ~= new foo();
       catch
       {
          printf("Allocated %d instances of foo.\n", fooa.length);
          break;
       }
    }

    return 0;
 }

 This one creates 15360 instances of foo whether on a Win95 machine 
 with 128MB or on a WinME with 256MB.  I searched the docs and could 
 not find anything.  Also, setting the length of the array to anything 
 over 245760 causes an Access Violation error.

 What am I missing?

 Thanks.
I don't think this is a limitation of D. It may be a limitation of Win9X. It probably also depends on the computer's available memory since each computer has a finite amount of RAM (even when you consider paging files). I have 128MB of RAM and I was running several programs at the same time. (I'm running WinXP Home.) This is what I got: Allocated 1411072 instances of foo. And I also got some friendly message boxes popping up telling me I was low on memory. And icons started disappearing.
With windows XP you can have a huge amount of virtual memory. Simply get a second hard rive and make a few GB virtual memory on each drive. I think win95 wasn't (isn't) so flexible in this way. Still virtual memory is slowwwww. -- -Anderson: http://badmama.com.au/~anderson/
Jan 23 2004
parent Paul Runde <prunde consolidated.net> writes:
J Anderson wrote:
 J C Calvarese wrote:
 
 I don't think this is a limitation of D.  It may be a limitation of 
 Win9X.  It probably also depends on the computer's available memory 
 since each computer has a finite amount of RAM (even when you consider 
 paging files).  I have 128MB of RAM and I was running several programs 
 at the same time. (I'm running WinXP Home.)

 This is what I got:
 Allocated 1411072 instances of foo.

 And I also got some friendly message boxes popping up telling me I was 
 low on memory. And icons started disappearing.
With windows XP you can have a huge amount of virtual memory. Simply get a second hard rive and make a few GB virtual memory on each drive. I think win95 wasn't (isn't) so flexible in this way. Still virtual memory is slowwwww.
Maybe for large collections I should be using class allocators? But it is just odd that two machines with different OS versions and memory amounts would allocate exactly the same number of instances. And I would have expected the results above, but neither machine complained.
Jan 23 2004
prev sibling parent reply yaneurao <yaneurao_member pathlink.com> writes:
In article <busj6v$2dl2$1 digitaldaemon.com>, Paul Runde says...
This one creates 15360 instances of foo whether on a Win95 machine with 
128MB or on a WinME with 256MB.  I searched the docs and could not find 
anything.  Also, setting the length of the array to anything over 245760 
causes an Access Violation error.
it is a bug I had reported. http://www.digitalmars.com/drn-bin/wwwnews?D/22303 and I wrote how to fix it. by rebuilding phobos such as the following article, it'll be fixed. http://www.digitalmars.com/drn-bin/wwwnews?D/21217 yaneurao.
Jan 23 2004
next sibling parent reply Manfred Nowak <svv1999 hotmail.com> writes:
yaneurao schrieb:

[...]
 by rebuilding phobos such as the following article, it'll be
 fixed. 
 http://www.digitalmars.com/drn-bin/wwwnews?D/21217
Cannot rebuild phobos: | std\thread.d(337): undefined identifier GetCurrentProcess Where is the trick? So long. -- Fight Spam! Join EuroCAUCE: http://www.euro.cauce.org/ 2EA56D6D4DC41ABA311615946D3248A1
Jan 24 2004
parent reply yaneurao <yaneurao_member pathlink.com> writes:
In article <buv4go$aun$1 digitaldaemon.com>, Manfred Nowak says...
Cannot rebuild phobos:
| std\thread.d(337): undefined identifier GetCurrentProcess
Where is the trick?
it needs forward declaration like this: extern(Windows) export void* GetCurrentProcess(); // void* is an alias of HANDLE yaneurao.
Jan 24 2004
parent Manfred Nowak <svv1999 hotmail.com> writes:
yaneurao wrote:

 it needs forward declaration like this:
 
 extern(Windows) export void* GetCurrentProcess();
 // void* is an alias of HANDLE
thnx. extern(Windows) export thread_hdl GetCurrentProcess(); played the trick. So long.
Jan 25 2004
prev sibling next sibling parent Paul Runde <prunde consolidated.net> writes:
yaneurao wrote:

 
 
 it is a bug I had reported.
 
 http://www.digitalmars.com/drn-bin/wwwnews?D/22303
 
 and I wrote how to fix it.
 by rebuilding phobos such as the following article, it'll be fixed.
 
 http://www.digitalmars.com/drn-bin/wwwnews?D/21217
 
 yaneurao.
 
 
That did the trick. Thanks. Paul
Jan 25 2004
prev sibling parent "Walter" <walter digitalmars.com> writes:
"yaneurao" <yaneurao_member pathlink.com> wrote in message
news:bustsi$2u0b$1 digitaldaemon.com...
 and I wrote how to fix it.
 by rebuilding phobos such as the following article, it'll be fixed.

 http://www.digitalmars.com/drn-bin/wwwnews?D/21217
I have the fix folded in now. Thanks.
Feb 02 2004