Question about memory allocation



 DEVELOP > c-Plus-Plus > Question about memory allocation

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "laniik"
Date: 07 Apr 2005 09:01:50 PM
Object: Question about memory allocation
I am relativly new in c++, so Im not entirely sure about how the memory
allocation stuff works. My problem is that i am running out of memory
after what is seemingly a very small amoune of memory allocation.
i have a class:
struct Point{
void set(int,int,int);
float distance(Point);
int x,y,z;
};
i am doing all my allocations with new, for example:
Point* points = new Points[256];
(which i do 4 times)
(i am making sure to delete[] points; however, my program is crashing
before it even gets to the deletes)
i get crashes in built in functions like strlen(). which im assuming
just means that i am out of memory, OR that my memory has become
corrupted. but just 1024 instances of a small class cannot be anywhere
near the maximum amount of memory that I can use in a program can it?
is there anyway to allocate more memory?
Thanks!
Oliver
.

User: "Mark P"

Title: Re: Question about memory allocation 07 Apr 2005 09:14:46 PM
laniik wrote:

I am relativly new in c++, so Im not entirely sure about how the memory
allocation stuff works. My problem is that i am running out of memory
after what is seemingly a very small amoune of memory allocation.

i have a class:

struct Point{
void set(int,int,int);
float distance(Point);
int x,y,z;
};

i am doing all my allocations with new, for example:

Point* points = new Points[256];
(which i do 4 times)

(i am making sure to delete[] points; however, my program is crashing
before it even gets to the deletes)

i get crashes in built in functions like strlen(). which im assuming
just means that i am out of memory, OR that my memory has become
corrupted. but just 1024 instances of a small class cannot be anywhere
near the maximum amount of memory that I can use in a program can it?
is there anyway to allocate more memory?

Unless you're running on a Vic-20 it's nearly certain that you're not
running out of memory from allocating ~3K integers. Unfortunately,
since you haven't posted complete code, there's no way for us to divine
what you are doing wrong. (hint hint...)
.
User: "Alan Brown"

Title: Re: Question about memory allocation 07 Apr 2005 11:56:47 PM
Mark P <not@my.real.email> wrote in
news:qOl5e.746$RQ7.111@newssvr14.news.prodigy.com:

laniik wrote:

I am relativly new in c++, so Im not entirely sure about how the memory
allocation stuff works. My problem is that i am running out of memory
after what is seemingly a very small amoune of memory allocation.

i have a class:

struct Point{
void set(int,int,int);
float distance(Point);
int x,y,z;
};

i am doing all my allocations with new, for example:

Point* points = new Points[256];
(which i do 4 times)

(i am making sure to delete[] points; however, my program is crashing
before it even gets to the deletes)

i get crashes in built in functions like strlen(). which im assuming
just means that i am out of memory, OR that my memory has become
corrupted. but just 1024 instances of a small class cannot be anywhere
near the maximum amount of memory that I can use in a program can it?
is there anyway to allocate more memory?


Unless you're running on a Vic-20 it's nearly certain that you're not
running out of memory from allocating ~3K integers. Unfortunately,
since you haven't posted complete code, there's no way for us to divine
what you are doing wrong. (hint hint...)

Running C++ on a VIC-20 Wow!!!!
Now there's a idea
Alan
.
User: "Mark P"

Title: Re: Question about memory allocation 08 Apr 2005 01:48:20 AM
Alan Brown wrote:

Mark P <not@my.real.email> wrote in

Unless you're running on a Vic-20 it's nearly certain that you're not
running out of memory from allocating ~3K integers. Unfortunately,
since you haven't posted complete code, there's no way for us to divine
what you are doing wrong. (hint hint...)



Running C++ on a VIC-20 Wow!!!!

Now there's a idea

It was the first thing that came to mind since I used to have a Vic-20
with 4K RAM and 3000 integers seemed about the right amount to exhaust
the memory. :)
.



User: "Scott McPhillips [MVP] org-dot-mvps-at-scottmcp"

Title: Re: Question about memory allocation 08 Apr 2005 12:29:10 AM
laniik wrote:

I am relativly new in c++, so Im not entirely sure about how the memory
allocation stuff works. My problem is that i am running out of memory
after what is seemingly a very small amoune of memory allocation.

i have a class:

struct Point{
void set(int,int,int);
float distance(Point);
int x,y,z;
};

i am doing all my allocations with new, for example:

Point* points = new Points[256];
(which i do 4 times)

(i am making sure to delete[] points; however, my program is crashing
before it even gets to the deletes)

i get crashes in built in functions like strlen(). which im assuming
just means that i am out of memory, OR that my memory has become
corrupted. but just 1024 instances of a small class cannot be anywhere
near the maximum amount of memory that I can use in a program can it?
is there anyway to allocate more memory?

Thanks!

Oliver

Your assumptions that you are out of memory are wild speculation. Wrong
theory. You will have to actually debug your code to get a better idea
of what is going wrong.
--
Scott McPhillips [VC++ MVP]
.

User: "Dirk Wendland"

Title: Re: Question about memory allocation 08 Apr 2005 02:16:54 AM
laniik wrote:

I am relativly new in c++, so Im not entirely sure about how the memory
allocation stuff works. My problem is that i am running out of memory
after what is seemingly a very small amoune of memory allocation.

i have a class:

struct Point{
void set(int,int,int);
float distance(Point);
int x,y,z;
};

i am doing all my allocations with new, for example:

Point* points = new Points[256];
(which i do 4 times)

(i am making sure to delete[] points; however, my program is crashing
before it even gets to the deletes)

i get crashes in built in functions like strlen(). which im assuming
just means that i am out of memory, OR that my memory has become
corrupted. but just 1024 instances of a small class cannot be anywhere
near the maximum amount of memory that I can use in a program can it?
is there anyway to allocate more memory?

Thanks!

Oliver

Hi
this Source works on my System ( GCC 3.X )
#include <stdio.h>
struct Point{
float distance(Point);
void set( int , int , int );
int x,y,z;
};
int main()
{
Point* points = new Point[256];
Point* points2 = new Point[256];
Point* points3 = new Point[256];
Point* points4 = new Point[256];
delete points;
delete points2;
delete points3;
delete points4;
printf("HI");
return 0;
}
.... No probmlem ....
Greetings
Drk
--
develop - Projekt
A Tool for c-c++ / java / html / php
http://dirk-wendland.de.vu
.
User: "Andre Caldas"

Title: Re: Question about memory allocation 08 Apr 2005 06:24:14 AM

delete points;
delete points2;
delete points3;
delete points4;

Usually you should do:
delete [] points;
delete [] points2;
delete [] points3;
delete [] points4;
.
User: "laniik"

Title: Re: Question about memory allocation 08 Apr 2005 12:20:41 PM
hm the reason i thought it was running out of memory is that it was
crashing when i was trying to allocate more memory, and the get last
error was "out of memory". both new and malloc gave me identical
results. (malloc returns a pointer to 0x0000000)
.
User: "Default User"

Title: Re: Question about memory allocation 08 Apr 2005 01:35:36 PM
laniik wrote:

hm the reason i thought it was running out of memory is that it was
crashing when i was trying to allocate more memory, and the get last
error was "out of memory". both new and malloc gave me identical
results. (malloc returns a pointer to 0x0000000)

You are almost certainly corrupting the free store with some sort of
undefined behavior. What we need is a minimal, complete program that
demonstrates the problem. Possibly in cutting down your program, you'll
discover whatever is causing the problem.
Brian
.





  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER