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 5 14159
res7c...@verizo n.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
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.remov e(Object o) instead of ArrayList.remov e(int index)
maybe i should just make a function that searches the vector and use
std::vector::er ase() 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
Oh, and also are there any guidelines/requirements for the objects
being inserted into the vector?
Thanks for a quick reply! re******@verizo n.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.remov e(Object o) instead of ArrayList.remov e(int index) maybe i should just make a function that searches the vector and use std::vector::er ase() 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
res7c...@verizo n.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 would be
declared in the body of the Main() and not inside the using (even not
referenced in the using) ? Would be there something to call to dispose
them ?
|
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 TrackSelection. I don't
know what I'm doing wrong. All the classes (that I need for COM) seem to
follow the requirements for COM interop.
Code for Item -> http://www.skidmore.edu/~h_blackw/Item.cs
Code for TrackSelection ->...
|
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 i load the dll everything is fine and when i load then the objects into
an Hashtable or Arraylist of the main program it freezes 5MB each which i
don't get free. The weird think is, when i reload the Tables a second time
on a new local variable...
|
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
NameStruct lnames; //This is a structure in C#
|
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
| |
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 resulting image back in some
other bitmap.
It works pretty fast, except for stages of coping pixels between bitmap
(object of type Bitmap) and the ArrayList. I'm using the trivial
|
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.
Thanks.
|
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 wanted to move to generics but the List<Tcollection does not
|
by: Saad |
last post by:
Hi,
I have a struct as follows:
public __gc struct STTemp
{
public:
int someint;
System::Collections::ArrayList* arrTemp;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |