|
From: <ste...@ge...> - 2001-01-10 04:13:08
|
Try this;
read some entry and then something like; (change the type of variable so =
it's suitable for the entries.)
entry_var =3D new int[size_of_entry];
if(!entry_var)
{
cout << "Unable to allocate memory!";
getch();
exit(-1);
}
do your stuff with the entries, and then remember to delete it like =
this;
delete(entry_var);
----- Original Message -----=20
From: "Alan Thomas" <ala...@3n...>
To: <dev...@li...>
Sent: Tuesday, January 09, 2001 7:00 PM
Subject: [Dev-C++] dynamic array
> How do you dynamically allocate space for an array? I have a
> program that works but is awkward in one aspect and potentially slow =
(for
> large input files). It performs operations on a file containing a
> particular format of calendar entries. Because I did not wish to =
initially
> deal with dynamically allocating memory as I read in calendar entries, =
I
> first read through the file just cueing on an end of entry character, =
to
> count the number of entries. Then I declare an array of the =
appropriate
> size, which will be used to hold processed information for each entry.
>=20
> This works fine for current input file sizes, but could =
slow
> things down noticeably if the input file was an order of magnitude =
larger.
> So, the alternative would be to allocate space as I read in entries.
>=20
> Thanks, Alan
>=20
>=20
>=20
>=20
>=20
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users
>=20
|