RE: [Dev-C++] dynamic allocation and structs
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2002-10-25 10:54:19
|
Exactly why my previous mail specified use-cases. - Sparse matrix, where a lot of entries are NULL. - Quick sort, since it's enough to move the pointers. - Different object types for each index, simulating C++ abstract base class. - Supports large vector in 16-bit code, where it's possible to have 16000 entries of up to 64000 byte size each. /Per W On Fri, 25 Oct 2002, Ioannis Vranos wrote: > > -----Original Message----- > > From: Ioannis Vranos [mailto:no...@ho...] > > Sent: Friday, October 25, 2002 12:39 PM > > To: Dev-C++ Mailing List (dev...@li...) > > Subject: RE: [Dev-C++] dynamic allocation and structs > > > > > > > -----Original Message----- > > > From: Per Westermark [mailto:pw...@ia...] > > > Sent: Friday, October 25, 2002 11:51 AM > > > To: Ioannis Vranos > > > Cc: 'Dev-C++ Mailing List' > > > Subject: RE: [Dev-C++] dynamic allocation and structs > > > > > > > > > The trick is that vector isn't programming. It is a standard > > > - and very > > > old - mathematical term for a one-dimensional matrix. > > > > > > Yes, but when we speak of C++ code, calling a built in array > > a "vector" can only be confusing. > > > > > > > > > There has been > > > millions of vector implementations before STL did a template > > > version, and > > > the probability of a finding a STL construct in a C program > > > is not that > > > high :-) > > > > > > Yes, but it still can be confusing to C++ programmers. > > > > > > > > > > > > While code might syntactically switch around between > > > (*a).x, > > > a->x > > > a[0].x > > > > > > the third form is definitely dangerous to use when a is only > > > a pointer to > > > a single element. If there is an element zero, the logical > > > conclusion is > > > that there must be a element one. > > > > > > Yes, if there is only one element i would use the -> only. > > When we have more the [] is more suitable. Both are valid. > > Also i cannot understand why someone would create a single dimensional > array of pointers on the free store and then assign an element on the > free store to each of them. It's a total waste of everything. :) Using a > simple pointer and allocating space for the elements directly on the > free store would be a reasonable thing to do. > > /* Array of 100 mystructs on the free store */ > struct mystruct *p=malloc(100*sizeof(*p)); > > > > Ioannis > > * Ioannis Vranos > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL: http://run.to/noicys > > > ------------------------------------------------------- > This sf.net email is sponsored by: Influence the future > of Java(TM) technology. Join the Java Community > Process(SM) (JCP(SM)) program now. > http://ads.sourceforge.net/cgi-bin/redirect.pl?sunm0004en > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |