🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: hepnet.lang.c++
Article #8

Re: dynamicaly allocating a two dim. array

#8
From: Dietmar Kuehl
Date: Tue, 31 Oct 1995 13:20
43 lines
1686 bytes
Jarmo Paavilainen (skorpio@dataphone.se) wrote:
: In message <46d9ak$c5h@ixnews7.ix.netcom.com> - techman2@ix.netcom.com (Peter 
: Dennis ) writes:
: 
: :> float array[x][y];
: 
: First C++ version
  C version using C++'s new:
: 
: float **array;
: 
: array = new float*[x];
: for(i = 0;i < x;i++)
:  { array[i] = new float[y]; }

Real C++ version:

  vector<vector<float> > array(x, vector<float>(y));

: and then C
: 
: float **array;
: 
: array = (float**)malloc(sizeof(float)*x);
: for(i = 0;i < x;i++)
:  { array[i] = (float*)malloc(sizeof(float)*y); }
: 
: Code not tested but it should work ( the C++ version anyway ).
: 
: 
: Take care,
: Skorpio
: 
: ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͻ
: ºJarmo Paavilainen ( alias : Skorpio ) ³e-mail : skorpio@dataphone.se  º
: ºSweden                                ³home   : ?                     º
: ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
: 

--
dietmar.kuehl@uni-konstanz.de
http://www.informatik.uni-konstanz.de/~kuehl
I am a realistic optimist - that's why I appear to be slightly pessimistic
Technical Details
Message-ID: <4757rk$cq6@eurybia.rz.uni-konstanz.de>
Path: arc1-ca.pugleaf.net!news.uni-konstanz.de!uzwil!kuehl
References: <474ljk$551@nic.dataphone.se>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.uni-konstanz.de!uzwil!kuehl
From: kuehl@uzwil (Dietmar Kuehl)
Newsgroups: hepnet.lang.c++,comp.lang.c,comp.lang.c++,cern.c++
Subject: Re: dynamicaly allocating a two dim. array
Date: 31 Oct 1995 13:20:52 GMT
Organization: Fakultät für Mathematik und Informatik
Distribution: world
Message-ID: <4757rk$cq6@eurybia.rz.uni-konstanz.de>
References: <474ljk$551@nic.dataphone.se>
Reply-To: dietmar.kuehl@uni-konstanz.de
NNTP-Posting-Host: uzwil.informatik.uni-konstanz.de
X-Newsreader: TIN [version 1.1 PL6]