Re: [Cppcms-users] Why isn't request const correct?
Brought to you by:
artyom-beilis
|
From: Artyom B. <art...@ya...> - 2014-07-30 11:11:43
|
Actually Marcel you noted correctly. Internally we use string_map (I'll explain why) and not std::(unordered_)map due to a very simple fact. string_map uses ONE allocation of memory that is created and released at once. When you get the CGI variables you don't use 95% of them. So when request comes it isn't cost effective to create a map object. It just uses a set of char * and a chunk of memory. It wasn't this way some (many) versions back but it had changed as optimization. The allocation was one of the major bottle necks in the system that was significantly reduced with string_map... (We talk about performance, aren't we?) Now why not const? Because it isn't "just" a container. I want to keep an option to have an optimizations like lazy allocation or some may require "recalculation on demand" that is why non-const is specifically defined as it may actually alter the class on demand in future (like some of the function already do). So no-const there by design and isn't a bug. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >________________________________ > From: Marcel Hellwig <ke...@co...> >To: cpp...@li... >Sent: Wednesday, July 30, 2014 1:39 PM >Subject: Re: [Cppcms-users] Why isn't request const correct? > > > > > > > > >On 30.07.2014 07:26, Noah Roberts wrote: >> std::string auth_type(); >> Does that function really alter the instance in an observable way? That it's non-const would indicate that it is, but I don't understand what it would change. > >That's an interesting fact and a bug imho. >As far as I can see, the problem is, that auth_type calls impl something >and then getenv (private/cgi_api.h). The connection class has a >string_map, where it stores its values and here is the problem. Why do >you use a custom string_map artyom and not a classic >std::(unordered_)map. The get_safe method (in fact all get functions) >are not const, because they call sort. But that's not necessary imho. >You just have to sort the map whenever you insert an element, but not >get one. > >So, two solutions: >1. get rid of the string_map and use a c++ (unordered_)map >2. Don't use sort in the get* method > > >Marcel > > > >------------------------------------------------------------------------------ >Infragistics Professional >Build stunning WinForms apps today! >Reboot your WinForms applications with our WinForms controls. >Build a bridge from your legacy apps to the future. >http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk > >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |