Topic: SV: Homegrown dynamic array
Author: oluies@my-deja.com
Date: 2000/02/11 Raw View
> The trouble is that I can't write one line of STL-using code until
> ALL of my compilers have STL support. As it stands today, I can't
> write one line of code that uses namespaces, or even exceptions,
> for the same reason.
The stlport project supports a lot of different C++ compilers:
http://www.stlport.org/doc/platforms.html
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: David R Tribble <david@tribble.com>
Date: 2000/01/19 Raw View
Pablo de Heras Ciechomski wrote:
> I've made this dynamic array because I have a New Year resolution
> not to use STL :=)
Niklas Pettersson wrote:
> I think you should reconsider your new year resolution... Using STL
> is an easy way to get your programs more standardized and portable.
Provided, of course, that all your compilers have an STL. That isn't
the case with most commercial C++ compilers today. It's not true of
all the Unix compilers I use at work, and probably won't be until
late this year.
The trouble is that I can't write one line of STL-using code until
ALL of my compilers have STL support. As it stands today, I can't
write one line of code that uses namespaces, or even exceptions,
for the same reason.
Hopefully, though, I won't have to post this same letter next January.
-- David R. Tribble, david@tribble.com, http://david.tribble.com --
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Niklas Pettersson" <npedt97@student.vxu.se>
Date: 2000/01/14 Raw View
I think you should reconsider your new year resolution... Using STL is an
easy way to get your programs more standardized and portable.
A few quick considerations of your class... Consider to make it with
templates to avoid casting (casting is often a hint that the design is bad).
You should also consider why you have the representation is protected
instead of private.
/ Niklas
Pablo de Heras Ciechomski <d96pd@efd.lth.se> skrev i
diskussionsgruppsmeddelandet:LY3f4.8614$yn3.18128@nntpserver.swip.net...
> Hi,
>
> I've made this dynamic array because I have a New Year resolution not to
use
> STL
> :=)
>
> A usage example is this:
>
> CFT_Array array;
> array.Create(5,sizeof(CFT_ComplexClass));
>
> ((CFT_ComplexClass*)array[0])->GetComplexNumber();
>
> I'm concerned with the speed of the overloaded [] member method. It uses a
> multiply fo each array acces, which I don't know if it will be optimized
by
> the compiler.
>
> Another way would be to use
>
> ComplexClass *array=new ComplexClass[5];
>
> array[0].GetComplexNumber();
>
> I hope they are equal.
>
> /Thanks in advance
>
> --
> /Pablo de Heras Ciechomski
> Computer Science and Technology student
> at Lund Institute of Technology in Sweden
>
> Here is code for the array
> ____________________________________________________________________
>
> #ifndef CFT_ARRAY_H
> #define CFT_ARRAY_H
>
> class CFT_Array
> {
> public:
> CFT_Array()
> {
> m_pArray=0;
> m_nNbrElements=0;
> m_nElementSize=0;
> };
>
> ~CFT_Array()
> {
> Delete();
> };
>
> int GetNbrElements()
> {
> return m_nNbrElements;
> }
>
> void Create(int nElements,int nSize)
> {
> Delete();
> m_nNbrElements=nElements;
> m_nElementSize=nSize;
> m_pArray=new char[m_nNbrElements*m_nElementSize];
> }
>
> void* operator[](int nNbr)
> {
> return (void*)&m_pArray[m_nElementSize*nNbr];
> }
>
> protected:
> void Delete()
> {
> delete [] m_pArray;
> m_pArray=0;
> m_nNbrElements=0;
> m_nElementSize=0;
> }
>
> int m_nNbrElements;
> int m_nElementSize;
> char *m_pArray;
> };
>
> #endif
>
>
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "E. Robert Tisdale" <edwin@netwood.net>
Date: 2000/01/14 Raw View
Niklas Pettersson wrote:
> Using STL is an easy way
> to make your programs more standardized and portable.
It is a good idea to use standard class libraries.
It is NOT a good idea to use standard type names
in the body of your application source code.
It is better to define and use synonyms such as
typedef float Single;
typedef double Double;
near the top of your source code
so that you only need to edit the definition
if you change your mind later.
This is especially important for standard class templates.
You should define and use synonyms such as
typedef valarray<float> SingleArray;
typedef valarray<double> DoubleArray;
so that you can substitute your own implementation
of SingleArray or DoubleArray later
if you determine that the implementation
in your standard library is inappropriate for some reason.
You may be obliged to write
#define Array valarray
so that you can use it to define templates
template<class T>
class X {
Array<T> v;
// ...
};
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]