|
-
Oct 25th, 2001, 07:42 PM
#1
Thread Starter
PowerPoster
Dymanic Array
hei buddies, have more than a month did login this forum . "coz juz busy with a project and now I juz stuck in somewhere else and need your expert to get me out from the dark 
what is the good what to write a dynamic array in C++/VC++? I have to store the following item in the array:
PHP Code:
typedef struct tagLANDMARK
{
TCHAR Place[33];
TCHAR type[33];
long Ptr;
RECT rt;
} LANDMARK;
I use UNICODE here is because the app is running on WinCE and it should not have any significant in coding 
regards,
Chris.C
Last edited by Chris; Oct 25th, 2001 at 07:51 PM.
-
Oct 25th, 2001, 07:49 PM
#2
I think the easiest way to create a dymanic array would be to use the ready-made vector class. Otherwise you'd have to create your own linked-list or binary-tree class.
Code:
vector<int> myVar;
// Add objects to the vector
myVar.push_back(43);
myVar.push_back(466);
myVar.resize(10);
myVar[8] = 43;
-
Oct 26th, 2001, 02:13 AM
#3
transcendental analytic
An array provides instant random access unlike linked lists and trees
A dynamical array is allocated on the heap, and access is provided with a pointer.
allocation:
type* array = new type[elements];
random access:
array[element];
destruction:
delete[] array;
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 27th, 2001, 04:44 AM
#4
Megatron: if he is codeing for WinCE, using vector might not be a good idea...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 27th, 2001, 11:24 AM
#5
kedaman: While that is a dymanic array, it cannot be resized without losing all the data that was originally in it. (unless you write your own function to loop through the elements and add them to the new array)
-
Oct 27th, 2001, 11:59 AM
#6
transcendental analytic
well thats how you do it usually 
template <class T>
T* resize(T*& x,int size){T* temp=(T*)memcpy(new T[size],x,_msize(x));delete[]x;return x=temp;}
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 28th, 2001, 03:07 PM
#7
kedaman, you sure know how to make code totally illegible. But it is cool nevertheless - I never thought there's such a cool way to take advantage of the fact that memcpy returns the address of the buffer.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 28th, 2001, 04:58 PM
#8
transcendental analytic
readability vs elegance
I prefer elegance, because it's cool, and in some cases like this, also profitable in performance
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 28th, 2001, 05:11 PM
#9
yeah, but splitting up the lines wouldn't hurt performance without decreasing performance. But personally I like code that I can read but not newbies
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 28th, 2001, 07:06 PM
#10
transcendental analytic
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|