Question about memory allocation

L

laniik

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
 
M

Mark P

laniik said:
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...)
 
A

Alan Brown

laniik said:
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
 
S

Scott McPhillips [MVP]

laniik said:
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.
 
M

Mark P

Alan said:
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. :)
 
D

Dirk Wendland

laniik said:
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
 
A

Andre Caldas

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

Usually you should do:
delete [] points;
delete [] points2;
delete [] points3;
delete [] points4;
 
L

laniik

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)
 
D

Default User

laniik said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top