473,692 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STL By object reference container to support real-time specs

18 New Member
What I'd like to do and what I tought possible was to have a deque of string when the string was a reference (not a pointer)

Then I simply tried:

std::deque<std: :string const &> mFifo;

But, the compiler have some trouble with this at the first try.

From what I know, template is a powerful mecanism an STL a well programmed library. I'm using VS2005 but STLPort seems with a quick look to suffer the same problem I will discuss shortly.

The thing is that I have a program running on Windows CE 5.0 which have some real-time specs. So, heap allocation in most case must be avoided. But I still want to use STL.

So. I tried to fix that with a user defined partial specialization of the allocator like this:

template<class _Ty>
class allocator<_Ty const &>

leaving the rest exactly the same. This should have work ... but ...

The deque contructor declared like this is making me wrong.
deque(size_type _Count, const _Ty& _Val)

This output: warning C4181: qualifier applied to reference type; ignored
and : //error C2529: '_Val' : reference to reference is illegal

Having coded the constructor like this would have fix the problem:
deque(size_type _Count, const_reference _Val)

typedef typename _Alloc::const_r eference const_reference ;

and where:
typedef const value_type _FARQ& const_reference ;

I wonder why I wasn't done like this. This would have make the STL library equivalent to .NET generics because with .NET the string class is readonly first and only references to it are used. So no copy, no heap allocation, then better runtime performance.

Unless I'm missing something important. After those many years STL, even though massively used, cannot offers much in the realtime world. Too much heap allocation, impossible to have object by reference containers. The complexity of algorithm is garantied but at the cost of a big constant time basic operations.

If some STL guru (like PJ Plauger) are somewhere out there and reading this, please help me with that or think about it in next version.

(Of course I can rewrite my own deque fixing those things, but that not point. user defined STL like container is not stanrard STL)
Jun 20 '07 #1
2 2085
9,208 Recognized Expert Moderator Expert
See my post on your later thread.
Jun 20 '07 #2
18 New Member
Ok. I saw it. But you don't understand.

In .NET, if you have a string object. The useful content is place somewhere in memory and referenced many many times.

List<string> is a list of reference to strings.

Also List<int> is a list of value type of int.

You then have best of both world. In C# you have pointer too in a unsafe context making possible miracles of runtime performance when needed. A programmer is then equipped with great tools to perform great tasks. Also the dispose pattern can bypass the garbage collector non deterministic behavior problems.

But, for those who still want more control, C++ is still the best solution. But STL, as it is right now, is far from useful.

std::deque<std: :string> is a deque of COPY of strings. Not references.

So I tought this possible:

std::deque<std: :string const &> .

This would have be what I wanted. My string are static const object allocated at the startup of the application and it is useless to create copies over and over during the live of the application.

But because the how the std::allocator is designed, it is impossible to do.

Allocator is and only is a HEAP allocator. You CAN'T create a reference by using the HEAP. So you can't have deque of reference. Point proven.

So far, unless a miracle occurs, I'm force to remove every STL reference in my apps and use C structure like container (fixed arrays, pointer and so on.)

More and more C++ community will be shadowed by .NET community because the people you propose standard use limiting set of rules and for the sake of pureness never wants to question them.

I used to be one of those.
Jun 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of a single collections type, I should be proposing a new "namespaces" module instead. Some of my reasons: (1) Namespace is feeling less and less like a collection to me. Even though it's still intended as a data-only structure, the use cases...
by: gman997 | last post by:
Hi all, At a high level here is what is going on -- I built a C# COM object. I need to call this com object from SQL Server using the sp_OACreate stored procedure in SQL Server. I build the COM object, register it using regasm, but when I try to call it in SQL Server I get the following error message - "0x80070002 Extended Procedure The system cannot find the file specified." I have tried registering the DLL with regsvr32 and that returns...
by: jsnX | last post by:
hi, i would like to make some code that operates on sets of points - does convex hulls and other operations. but it looks like i will need a lot of pointless object copies: ====================================================================================== // point cloud class class pc : public std::vector<vec2d> {
by: richard_l | last post by:
Hello All, Please see attached example code. I'm writing a program whereby I would like to reference an object from another object. For example I have an object called Value and I have created a reference to that object in the class Container by using Value& m_Val.
by: Laura K | last post by:
Hi. I am trying to put a drop down in a repeater. I had this working in dreamweaver but now I am trying to transfer it into VS. I am obviously missing something. I am getting the following error. "Object reference not set to an instance of an object" THe error is referring to the following line which is located in the function below.
by: | last post by:
Simple question, I think... I'm storing an object in the Session object. In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction) If I change any properties, I have to store it back into the session object to "update" it, right? Or will the changes to my object automatically be saved back into the session object? Thanks, Jerry
by: Andrew Poulos | last post by:
With "normal" SWF HTML there's an EMBED tag nested within an OBJECT tag. How can I check which tag is actually displaying the SWF? I'm using CSS on them and the style on the OBJECT affects the EMBED tag so I'm going to use some code to correct it but I can't tell which tag is responsible for the display. Andrew Poulos
by: better_cs_now | last post by:
Hello all, I suspect that a threading issue is leading to an object being destructed in one thread context while one of its member functions is still running in another thread context. As a means of confirming this, I would like to have the object check if it is alive in the referenced member function and report to me if it is not. However, I cannot think of a standards-compliant way for an object to know that it has been destructed.
by: subramanian100in | last post by:
Consider the code fragment: vector<intcontainer; container.insert(container.begin(), 10); int& ref = *--container.end(); From this, it looks like we can apply prefix decrement operator to container.end() - ie 'prefix --' can be applied to the iterator type
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
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: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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 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.