Question

TList vs. Vector // Delphi&Pascal vs. C++ // MS vs. Borland .....

Asked by: BdLm

----  a general question ----

How to compare Pascal TList Class vs. C++  vector and Maps , in terms of performance  (insert, update, ...)and coding properties (readability of code, efficiency of the programmer)

Any good link or article is needed.

Is the lack of a STL in Delphi a major drawback, will this help C++ to stay a more imprortant programming language compared to Pascal?

Best

Bdlm

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-10-19 at 02:58:47ID22904017
Tags

tlist

Topics

C++ Programming Language

,

Miscellaneous Programming

,

Pascal Programming Language

Participating Experts
5
Points
250
Comments
17

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. STL : Vector....
    I use VCPP5.0 with STL ( or I try using it...) I declared a class with a constructor, desctructor and so on... and I want to use it as in a vector... especially recursively ( a treestructure)... But it doesn't work.... e.g.: class XY { ... public: int m_member1; ... s...
  2. STL Vector
    I wanna represent a Table(list of records in a 2D stl::vector) and define an iterator for that container. Can anyone help!!! My table look like this ============================== NAME CostP SP Vol Size ============================== carpet 32.12 12.10 1000 large //si...
  3. Stl:Vector
    can I build a table using stl vector?? does it have to be a 2D vector then? coz I need to query the information thru name or ordinal position say for eg. querying like this; give me the value of the second field of the third row?? value of vec(2,3); or value of vec(bulls,3) o...
  4. C++ Vectors and STL
    Hi, Can anyone please give me an example of how can I use the STL to create a vector ? I would like to see examples of insert and remove from the vector. Tnx
  5. STL vectors
    I have to read a text file samp.txt and store line by line in STL vectors. That has 10 lines. I have to read the lines from 3 to 6 that start with the word "st" and ends with word "ed". Explain with the sample code.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: peprPosted on 2007-10-19 at 06:14:25ID: 20108571

I do not know details of TList. There is a list in C++ that will probably be more similar abstraction to the TList.

It is not fair to compare Pascal and C++. The C++ implements the STL using templates. Then the versatility of such implementation is higher. I am not sure if this can be easily compared generally, without having some testing example.

For Borland vs. MS: The C++ from Microsoft is considered very good. And it is likely that it will be even better in future as Microsoft closely cooperates on the future C++ standard (Herb Sutter being their most visible expert in the area).

 

by: developmentguruPosted on 2007-10-19 at 07:34:16ID: 20109176

 You need to compare the tools versus a particular use... different tool sets excel for different tasks.  Delphi is my tool of choice for Windows application development.  The language is much more readable than C++ in my opinion (assuming the same programmer on both languages).

  One of the very things that can make Delphi code faster (the way it handles it's call stack) is the same thing that limits some of the functionality the C++ developers like to bring up (how each language has to go about handling variable parameter lists).  The speed can be reached in C++ code as well, by using the same call stack approach (PASCAL), but then you limit your call stack the same way Delphi's is limited.

  Many C++ developers tout operator overloading as a major language enhancement that Delphi does not have.  I have only found limited areas that this is useful in my own code (one project in 20 years).  Delphi for .NET does allow operator overloading, not the Win32 variety as I understand it.

  The Delphi compiler is FAR faster than the C++ compiler.  In one instance I sat down with a person familiar with C++ compilers and showed him my delphi application running in the IDE.  He asked me, "Ok, now... what does it take to compile it into an application?".  I stared at him confused for a moment because it was alrady a running application (he had just witnessed the entire compilation progress and missed it).  This speed difference can make a huge impact on the time it takes to go through the development cycle.

  Having said all of that, C++ has uses that Delphi does not handle.  If you need to write an operating system, BIOS, or even code that will reside on a hardware board C/C++ is the choice.  Delphi is not designed for that kind of use.  If you want to write code that handles multiple OSes then C++ is likely your best bet as well (as a compiled language with native executable output... I would probably prefer Java or several others if native EXE output is not the goal).

...as a side note...
  For most development I would stay away form .NET... it is prone to cause "Pregnant pauses" during execution.  I know that many developers will claim that the garbage collection in .NET is so good that you will never see a pause from it... I have (1 to 5 seconds).  At least in the Delphi / C++ languages where you manage your own memory you do not run into unpredictable garbage collection delays.

  No one tool is not the best for all purposes.  Evaluate what you will be doing and make your decision based on that.  If most of what you will be doing is Windows development then, personally, I don't think anything comes remotely close to Delphi for being able to produce reliable, fast, code - quickly.  If you plan to do Windows development and other types, I would use multiple tools.  Choose the one that is right for your task.

 

by: dbkrugerPosted on 2007-10-19 at 14:33:35ID: 20112589

Realistically, Borland is a small abberation, and even if you don't love Microsoft (I don't) the world uses C++, Java, and C#. So in terms of the market, Delphi is a lost cause. I'm not commenting on the merits, because I don't know Delphi.

In terms of compile time, Java with Eclipse is very fast because it's incrmenetal, though it's not as fast as Delphi, probably. And that does make a big difference in programmer productivity. C++ has the most expressive power, which is occasionally really useful. When writing mathematical code, the ability to use overloaded operators and have vector equations look as they should is unbeatable.

Templates are a compile time mechanism that is a double win -- the resulting code can be super fast and efficient, while types are checked at compile time. If I want a list of Elephants, I don't want zebras creeping in there, only to crash at runtime, I want to know at compile time that I did something illegal.

 

by: BdLmPosted on 2007-10-20 at 14:10:34ID: 20116073

     The delphi / pacal code ...
------------------------------------------------------
      //  loop through all elements
      for i := 0 to MyNetList.Count -1 do
         begin
           myElement := MyNetList.Items[i];
           for j:=0 to MyElement.Nodes.Count-1 do
              begin
              If BiasNodes.IndexOf(MyElement.Nodes[j])=-1 then BiasNodes.Add(MyElement.Nodes[j]);
              end;
         end;


C++  STL   Code
---------------------

    for(std::vector<unsigned long>::const_iterator i = m_VectorElementID.begin();
            i!= m_VectorElementID.end(); ++i)
      {
            if(*i==id)
                  return ;            
      }
      m_VectorElementID.push_back(id);
      return;


here a short code comparisons, not same functionallity, but same complexity.
I can't post both applications code here.

We used a first application, written in pascal to read a txt file with 50,000 data records, store them in a Tlist, do some tiny modifications and dump the new List in  an XML File.  We used MSXML 6 API for  writeing  the XML file.  Run Time for 50.000 recoreds a  ~  minutes.

The second application, written in C++ reads this XML file, store the data in a MAP (dynamic array, our replacement for the TList Class from Pacal) and finally we have  to do other operations. Just reading the XML  and creating the MAP takes more then 2 hours. Again we used MS XML. With this ~ 100 times slower data processing we can not reach our performance targets

We have to access single records from our dynamic array, we have to modify single elements in this array, therefore we think, The pacal TList is much better than a vector or a Map from STL C++.
I want to get proofs or inputs how to compare this.  

 

by: peprPosted on 2007-10-21 at 23:21:02ID: 20121109

I believe that the problem is somewhere between the keyboard and your chair. I cannot see any similarity between the two code fragments. The control structures are completely different... also the operated data. It is impossible to comment on your XML example.

Some more comments: The std::map is not a dynamic array, it is a look-up table (the term map is generally used for that kind of data structure). The std::vector is a dynamic array, but it is not a list. List is not an array and if indexing of the list is syntactically allowed, then it will always be slower than the std::vector (in principle).

You should show how your XML records look like and what kind of processing you do. If processing the 50.000 records takes 2 hours, then you are processing about 7 records per second which is unrealistic for any usual program (even written in the scripting language).

 

by: BdLmPosted on 2007-10-22 at 01:31:08ID: 20121546

in both programs we init a dynamic array of a  defined Datastructure.   Data stuct look like
AElement =  .....  many type    subDynArray  :  Dynamic array  of  ASubdatatype;
What we have to execute in our program is llok for a Index of an Element, find the Index of a Subdatatype and to some small calc.
Our believe is, that the Indexof, Find an Element, Loop thorugh all elements is significant slower for vector and map  as for TList.  

For coorect analysis we should write the identical code in both languages and do our tests,
but I want to avoid this effort wuth with discussion here, looking for a explanation.
         

 

by: peprPosted on 2007-10-22 at 03:22:58ID: 20121990

From what I have read about TList (http://www.delphibasics.co.uk/RTL.asp?Name=TList), it seems that it is rather a dynamic array (than list) with some extra functionality. Arrays (including std::vector) are not the best choice for a structure that should be searched for some content.

Notice that you can use also indexing when accessing the element inside the std::vector -- and it is extremely fast operation. Try this:

=============================================
#include <vector>
#include <iostream>

using namespace std;

int main()
{
    vector<long> v;
    size_t vMax = 50000;

    cout << "reserve...";
    v.reserve(vMax);        # only to optimize allocation

    cout << "\nassign...";
    for (size_t i = 0; i < vMax; ++i)
    {
        if (i % 1000 == 0)
            cout << " " << i;
        v.push_back(i);
    }

   
    cout << "\nloop...";
    for (size_t i = 0; i < v.size(); ++i)
    {
        if (i % 1000 == 0)
            cout << i << ": " << v[i] << "\n";
    }

    cout << "\n(the end)\n";

    return 0;
}
=============================================

 

by: peprPosted on 2007-10-22 at 03:31:40ID: 20122022

If you really want to search for a content based on some key (say identification), you should use one of the avaliable map<> structures. Try this:

=============================================
#include <map>
#include <iostream>

using namespace std;

int main()
{
    map<long, size_t> m;
    long MAX = 50000;
   
    cout << "\nassign...";
    for (long i = 0; i < MAX; ++i)
    {
        long id = i * 2;         // just to simulate the ID
        size_t content = i * 3;  // ... and the content
        m[id] = content;         // insert the content for the id
    }


    cout << "\n";    
    cout << "id = 4; value = " << m[4] << "\n";
    cout << "id = 30000; value = " << m[30000] << "\n";

    cout << "\n(the end)\n";

    return 0;
}
=============================================

 

by: peprPosted on 2007-10-22 at 03:33:20ID: 20122031

Use "// only to optimize allocation" in the previous example instead of "# ..." (my mistake).

 

by: BdLmPosted on 2007-10-22 at 04:45:59ID: 20122354

many thanks in advance for you post,  I will check this code and than accept the question

 

by: itsmeandnobodyelsePosted on 2007-10-22 at 07:39:20ID: 20123495

>>>> Arrays (including std::vector) are not the best choice
>>>> for a structure that should be searched for some content.

That depends on the number of items and the order the entries were inserted. In case of less than 100 entries the differences in speed are some nanoseconds and you can go for the container you know best. For higher counts and in case you have a sorted array (TList or std::vector), you can lookup for a given value using a binary search algorithm (check whether the 'middle' item of the array is less or greater than the item searched for. Take either low or high part of array to search again, and so on ...) which is as fast as lookup in std::map but requires less storage and most likely quicker for insert than putting all pairs of key and value to a std::map. Of course using std::map (or an equivalent dictionary class in Borland) is much more comfortable than having to implement a binary search yourself. But as it is a one-time job of less than an hour work, I wouldn't made that a main criteria.

Regards, Alex

 

by: peprPosted on 2007-10-23 at 00:32:30ID: 20129148

BdLm: "We used a first application, written in pascal to read a txt file with 50,000 data records, store them in a Tlist, do some tiny modifications and dump the new List in  an XML File."

The question is whether you should not focuse more on searching for the "right" solution instead of focusing on improving the ad-hoc solution copied from the old application. In my opinion, you should learn basics of XML processing. It seems that some implementation of a SAX based parser may be the right approach for you (http://en.wikipedia.org/wiki/SAX). As you are using Windows, you can use MSXML components by Microsoft (http://en.wikipedia.org/wiki/MSXML) or XmlLite (http://msdn2.microsoft.com/en-us/library/ms752872.aspx).

I personally would probably start with samples that use XmlLite (http://msdn2.microsoft.com/en-us/library/ms752864.aspx).

 

by: developmentguruPosted on 2007-10-23 at 10:07:27ID: 20132556

pepr:
It's all well and good to use out of the box solutions to problems, and most of the time they work out well.  The only thing I hate to see in that regard is when developers become incapable of designing new solutions on their own due to the thought that there ar already "acceptable design patterns" that exist for this case.  While your program MUST be accurate, user friendly, etc you cannot deny the need for speed.  If, in any given situation, a design pattern you have inherited is not producing the results you want/need then by all means get creative!  I don't think any of this this addresses the original question though.

  I have not personally missed the C++ STL at all (while using Delphi).  Most templates I would need already have an implementation, or are easily derived (in minutes).  Now, having said that, you could easily do a TList in C++.  This would result in the same sort of speed you have in Delphi (with the exception of call stack performace, etc).  It would also give you a tool that is more comfortable to you if you are familiar with Delphi.  As I stated before, what it really comes down to is what you need for THIS project (any of the many you work on).  Make your decision on a case by case basis and you will optiize your development efforts vs end product quality every time.

 

by: peprPosted on 2007-10-23 at 23:48:24ID: 20136728

developmentguru: Well, it is always good to think about a solution. I agree that "rely on obscure 3rd party library" only because someone said it can be used is not good. However, "reinventing the wheel" in the case it is just around the corner is also not good. It is good to learn and to work hard all the time. However, in my opinion, it is better to use your creativity for the things that have not been solved, yet.

There is no "the best programming language". Both C++ and Delphi are not exceptions. But I have to partly agree with dbkruger about positions of the two languages. I believe that C++ is still more powerful and versatile. The dark side of C++ is that you have to learn more to be efficient in it. But after that, you are not limited. You can use your creativity the way it cannot sometimes be done in other languages.

To be short and back to the original question... I strongly believe that simply "using C++ instead of Delphi" is the reason for slowdown computation.

 

by: peprPosted on 2007-10-23 at 23:49:45ID: 20136735

correction: "I strongly believe that simply "using C++ instead of Delphi" is *NOT* the reason for slowdown the computation."

Of course... ;)

 

by: mipkoPosted on 2007-11-01 at 16:11:58ID: 20197354

check DCL for delphi.

http://sourceforge.net/projects/dclx

I think you will find very nice stuff in it.

Mirko

 

by: BdLmPosted on 2007-11-23 at 16:23:52ID: 20341301



We evaluated the code in more detail, as we use many insert elements in a list, search for a Element in List, we can't compare directly our delphi and our C++ application.  .-((

the Delphiapplication  does the operation in one direction , with the c++ app. we calculated the opposite direction.

MSXML and the msxl.dll seem to work fine for both compilers. The difference in performance is created by a difference in List and vector operations. we have to eval. out code in more details.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...