473,322 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Make ArrayList in Unmanaged C++

I like to implement and ArrayList like Java's and C# in C++
but I have no clue how to start
I really don't want to use Managed C++ and use ArrayList that way - I
want to keep it "unmanaged"

Can anyone point me to a resource that can tell me how to do this?

Thanks in advance

May 24 '06 #1
5 14146
res7c...@verizon.net wrote:
I like to implement and ArrayList like Java's and C# in C++
but I have no clue how to start
Well, the C++ standard library defines several different collection
class templates which are adequate for most purposes -- did you learn
about these before deciding that you have to implement your own? The
closest analogue to ArrayList is probably std::vector, because it's a
collection class implemented in terms of a contiguous block of memory
(an array).
I really don't want to use Managed C++ and use ArrayList that way - I
want to keep it "unmanaged"
You'll find that the culture of this group is fairly unsympathetic (at
times openly hostile) to nonstandard extensions such as Managed C++; as
such, most of us won't work very hard to decipher lingo specific to
such extensions. Do managed/unmanaged refer to, perhaps, garbage
collection or the lack thereof? C++ does not have garbage collection
(though of course it's possible to implement a GC system in C++), so I
guess that satisfies your desire to keep things "unmanaged."
Can anyone point me to a resource that can tell me how to do this?


Read up on the STL first, before deciding to roll your own. It's not
just a matter of reinventing the wheel -- proper use of at least the
basic STL containers is a fundamental C++ skill. Learning about them
is something every C++ programmer should do long before achieving the
necessary skill level to implement something analogous on his or her
own.

Get yourself a copy of Stroustrup's _The C++ Programming Language_.
For an online STL reference, see sgi.com/tech/stl (though beware of
their nonstandard extensions).

Luke

May 24 '06 #2
oh i didn't know STL had container classes - how cool - they even have
Iterators - perfect!
std::vector seems promising, but i'd like to remove objects based on
object search, not by index number
like ArrayList.remove(Object o) instead of ArrayList.remove(int index)
maybe i should just make a function that searches the vector and use
std::vector::erase() to get rid of it

is access to the ArrayList fast? i need to loop through the entire
vector to perform operations on them constantly (maybe use Iterators?)

also can there be a vector of pointers? all the examples i've seen use
non-pointers

May 24 '06 #3
Oh, and also are there any guidelines/requirements for the objects
being inserted into the vector?

Thanks for a quick reply!

May 24 '06 #4
re******@verizon.net wrote:
oh i didn't know STL had container classes - how cool - they even have
Iterators - perfect!
I'm gratified you think so.
std::vector seems promising, but i'd like to remove objects based on
object search, not by index number
You can do that. Keep reading.
like ArrayList.remove(Object o) instead of ArrayList.remove(int index)
maybe i should just make a function that searches the vector and use
std::vector::erase() to get rid of it
First, learn whether such a function already exists (hint: yes). Be
aware of the performance cost associated with removing from the middle
of a vector, though. std::list and std::deque might be worth
considering instead, if you need to do a lot of that kind of thing.
is access to the ArrayList fast?
You mean the vector? Sure, it's fast.
i need to loop through the entire
vector to perform operations on them constantly (maybe use Iterators?)
Yes, use iterators.
also can there be a vector of pointers? all the examples i've seen use
non-pointers


Yes.

Your enthusiasm is great, but you're asking pretty basic questions that
are more readily answered by simply doing some reading. Usenet is for
when you can't find the answer on your own.

Luke

May 24 '06 #5
res7c...@verizon.net wrote:
Oh, and also are there any guidelines/requirements for the objects
being inserted into the vector?
Yes, there are. They must have value semantics. Google for more.
Also, see the FAQ at http://www.parashift.com/c++-faq-lite/.
Thanks for a quick reply!


You're welcome. Please buy a book, though, or get one from your local
library. You'll relish the decision to do so, in the long term.

Luke

May 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Cybertof | last post by:
Hi ! I'm wondering about the use of the 'using' statement. In a procedure, should i declare all instance variables in a using clause ? In the below code, what would happen if MyFont & MyFont2...
8
by: Hasani | last post by:
The reason I ask this is because I'm having problems accessing an array of type TrackSelection in a VBS script I'm using to test my code. item.AdditionalInformation returns an array of type...
7
by: Matthias Kwiedor | last post by:
Hi@all! I have a app (c#) where i load up a external dll (managed code from c#) with a small arraylist and hashtable in two routines (about 40000 objects in each arraylist and hashtable). If...
5
by: GeRmIc | last post by:
Hi, I am doing an interop from unmanaged code to C#. How do i pass an ArrayList pointer from an unmanaged code, (structres are easily passed by between C# and C). //This is the C code ...
9
by: Steve | last post by:
Hello, I created a structure ABC and an array of type ABC Public Structure ABC Dim str1 As String Dim int1 As Integer End Structure Public ABC1 As New ABC, ABC2 As New ABC
3
by: Iwanow | last post by:
Hello! My goal is to develop a program that opens a bitmap, copies its pixels to an ArrayList in order to perform some complex calculations (edge detection, Hough transform etc.), and save...
94
by: Peter Olcott | last post by:
How can I create an ArrayList in the older version of .NET that does not require the expensive Boxing and UnBoxing operations? In my case it will be an ArrayList of structures of ordinal types. ...
5
by: info | last post by:
Hi All, Suppose you need to release unmanaged resources when you remove an item from a colletction. We are now using an override of the ArrayList.Remove() method that dows the job. We...
3
by: Saad | last post by:
Hi, I have a struct as follows: public __gc struct STTemp { public: int someint; System::Collections::ArrayList* arrTemp;
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.