advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Which of these two enhancements is more appealing to you, if either?
Partners & Affiliates
advertisement
advertisement
advertisement
Rate this item | 0 users have rated this item.
 
Spruce Up Your Built-in Arrays
Built-in arrays provide superior performance, but the trick is to use them without compromising STL compatibility. This solution will teach you to use built-in arrays properly and how to create an array whose dimensions are determined at runtime without having to resort to hefty dynamic memory allocation. 

advertisement
++ pundits recommend that you replace built-in arrays with st::vector across the board. Sometimes however, built-in arrays are unavoidable due to their unsurpassed efficiency or because your app must interact with external software e.g., a relational database or an XML schema. In the following sections I will present two techniques for enhancing this mundane feature: an array wrapper template, and a variable length array. When used judiciously, these enhancements enable you to use built-in arrays without sacrificing STL compatibility and without resorting to manual memory management, respectively.


How to use built-in arrays without compromising STL compatibility? Also, how to create an array whose dimensions are determined at runtime without the pains of dynamic memory allocation?


Use an array wrapper template and C99's variable length arrays, respectively.

Problem Analysis
When you need a container that grows and shrinks dynamically, st::vector is unquestionably the right choice. However, sometimes st::vector is used instead of a built-in array only for the sake of interoperability with other Standard Library components. Performance-wise, this technique isn't ideal: st::vector involves complex construction and destruction operations, it allocates elements on the free-store (even when their number is fixed and known at compile-time), and it isn't exactly a lightweight class. What you really want is the compactness and speed of built-in arrays, while still benefiting from an STL-like interface. You can achieve this by using a wrapper class template.

  Next Page: Step 1: Array Wrapping
Page 1: IntroductionPage 3: Step 2: Variable Length Arrays
Page 2: Step 1: Array Wrapping 
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES