|
From: Alan T. <ala...@3n...> - 2001-01-10 03:04:48
|
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.
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.
Thanks, Alan
|
|
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
|
|
From: Fabien V. <fv...@fr...> - 2001-01-10 11:31:14
|
With you're writting your program in C you can use: int (*buffer)[]; buffer=(int*)malloc(size_of_entry*sizeof(int)); Then you can use your variable "buffer" as you would do with any array. When you have finished to use your buffer do free(buffer); VIVES Fabien. ----- Original Message ----- From: "Alan Thomas" <ala...@3n...> To: <dev...@li...> Sent: Wednesday, January 10, 2001 4:00 AM 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. > > 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. > > Thanks, Alan > > > > > > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users > |
|
From: Ioannis V. <no...@ya...> - 2001-01-10 22:46:42
|
In C you can use malloc(), calloc() and realloc(). In C++ new and delete operators. Ioannis > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...]On Behalf Of Alan Thomas > Sent: Wednesday, January 10, 2001 5:01 AM > To: dev...@li... > 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. > > 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. > > Thanks, Alan > > > > > > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users > |
|
From: Ioannis V. <no...@ya...> - 2001-01-10 22:51:15
|
Although in C++ when you program in the recommended style, that is using the standard containers and the rest of high level constructs, you will almost never need to allocate manually memory space. In this way you have huge control of your code at the optimum speed and resource utilisation. Ioannis > -----Original Message----- > From: Ioannis Vranos [mailto:no...@ya...] > Sent: Thursday, January 11, 2001 12:49 AM > To: dev...@li... > Subject: RE: [Dev-C++] dynamic array > > > In C you can use malloc(), calloc() and realloc(). In C++ new and > delete operators. > > > Ioannis |
|
From: ShadowOz <sha...@da...> - 2001-01-10 23:46:14
|
Hello everybody Here´s my question: I´m trying to create a simple dll, with function I that want to be used by other application. Q: How can I make those functions acessible to the others applications? thx. Ae galera .pt, tá muito frio aí? :-) |