Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
K

Kosta Cherry

@Kosta Cherry
About
Posts
26
Topics
8
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Should I consider going back to school?
    K Kosta Cherry

    If company wants you to have a paper and sneezes at your experience, you don't wanna work for them. Really, you don't. You would regret it from day one of employment.

    The Lounge csharp php html design help

  • Google, EU, and $6B
    K Kosta Cherry

    Brent Jenkins wrote:

    The law can't be selectively applied

    You joking, right? In international relations the "law" is always "selectively applied". And whoever has the louder TV - wins.

    The Lounge help algorithms tutorial question

  • Time for a new programming language paradigm
    K Kosta Cherry

    It's time to scratch all other languages and just leave C++ alone. Honestly, I used to write in many diff languages - about 18 of them. And you know what? I got tired. Every few months there is new, "latest and greatest" mumbo-jumbo that employers jump onto - hey, look, new buzzword. And poor programmers have to "learn", i.e. stuff into their heads that "new" APIs, new language things - just to have them to disappear in another few months for another mumbo-jumbo. Enough for me. I don't want to waste my life permanently studing things that will gone few months down the road. And, even if they stay - sorry, no. I chose C++, get great at it, and keep it that way.

    The Lounge linux tools c++ java javascript

  • Problem with const struct initialization in a class
    K Kosta Cherry

    OK, this is not the most elegant solution, but here we go:

    charBoundary getInitialBoundary()
    {
    charBoundary c ={2,-5};
    return c;
    }

    class foo{
    public:
    foo() : versionBoundary(getInitialBoundary()) {}
    private:
    const charBoundary versionBoundary;
    };

    C / C++ / MFC question c++ help announcement

  • Pattern matching in trees, lists and strings alike
    K Kosta Cherry

    You can do anything in C++. your example can be done as this:

    std::string mystdarr[][2] = {{"Abel","Hirst"},{"Benjamin","Foster"},{"Letty","Johnson"},{"George","Hanson"},{"Chris","Johnson"},{"Priscilla","Stein"}, {"",""}};
    int arrsize = sizeof(mystdarr)/sizeof(mystdarr[0]);
    for (auto it=0; it < arrsize - 1; ++it) {
    auto itFound = std::find_if(&mystdarr[it+1], &mystdarr[arrsize-1], [&](const std::string (&cmp)[2]) { return !cmp[1].compare(mystdarr[it][1]); });
    if (itFound != (std::string (*)[2])(mystdarr[arrsize-1]))
    std::cout << mystdarr[it][0].c_str() << " and " << (*itFound)[0].c_str() << " have the same family name (" << (*itFound)[1].c_str() << ")\n";
    }

    Or, if you'd like less cryptic code (it's cryptic because built-in arrays in C/C++ are by no means flexible), you can do this:

    struct SS
    {
    std::string firstName;
    std::string lastName;
    SS(const std::string& fname, const std::string& lname) : firstName(fname), lastName(lname) {};
    };
    std::vector myarr;
    myarr.push_back(SS("Abel", "Hirst"));
    myarr.push_back(SS("Benjamin", "Foster"));
    myarr.push_back(SS("Letty", "Johnson"));
    myarr.push_back(SS("George", "Hanson"));
    myarr.push_back(SS("Chris", "Johnson"));
    myarr.push_back(SS("Priscilla", "Stein"));
    for (auto it=myarr.begin(); it!=myarr.end(); ++it)
    {
    auto itFound = std::find_if(it + 1, myarr.end(), [&](const SS& cmp) {return !cmp.lastName.compare(it->lastName);});
    if (itFound != myarr.end())
    std::cout << it->firstName.c_str() << " and " << itFound->firstName.c_str() << " have the same family name (" << it->lastName.c_str() << ")\n";
    }

    Algorithms regex c++ html com hardware

  • VC++ and Empty Base Class Optimization problem/bug
    K Kosta Cherry

    Standalone one - yes. But we are talking here about descendants, where empty class/struct can be eliminated. This is called Empty Base Class Optimization (you can google for it).

    C / C++ / MFC help c++ algorithms debugging performance

  • VC++ and Empty Base Class Optimization problem/bug
    K Kosta Cherry

    Well, consider the following struct: struct JustString: public std::string { }; It has the same size as just std::string, so no, there is no extra pointer in VFT. The question I have is about Empty Base Class Optimization - size of empty base class should be reduced to zero in descendant if possible. Yes, it is not a requirement, only a suggestion in a standard. Problem is, I don't understand this: it works for non-MS compilers; in MS-compiler it works for all cases EXCEPT std:string. I will check later with VC++ 2012 to see if they made it work, but right now I have no other explanation than some problems with MS compiler. Or is there any compiler option specifically for this case that I don't know about?

    C / C++ / MFC help c++ algorithms debugging performance

  • VC++ and Empty Base Class Optimization problem/bug
    K Kosta Cherry

    Here is the test code: http://codepad.org/zKTatneG[^] struct Empty { }; struct JustLong { long data; }; struct LongAndEmpty : public JustLong, private Empty { }; struct StringAndEmpty: public std::string, private Empty { }; int main() { cout << "Empty:" << sizeof(Empty) << endl; cout << "JustLong:" << sizeof(JustLong) << endl; cout << "String:" << sizeof(std::string) << endl; cout << "LongAndEmpty:" << sizeof(LongAndEmpty) << endl; cout << "StringAndEmpty:" << sizeof(StringAndEmpty) << endl; return 0; } When you try it in other compiler (for example, see link above for codepad.org), results are correct, i.e. output looks like this: Empty:1 JustLong:4 String:4 LongAndEmpty:4 StringAndEmpty:4 Now, when you try this in VC++ (2010), size of struct with std::string is always (debug and release) 4 more that size of just std::string. Any other structs/classes are of correct size, and only those with std::string are bigger than they should be. Am I missing something or this is MS bug?

    C / C++ / MFC help c++ algorithms debugging performance

  • C++ GUI Framework
    K Kosta Cherry

    Richard MacCutchan wrote:

    How do you define "good"? Lots of people use either one of these and are quite happy with them; others use WinForms in C# or VB.NET, still others use WPF.

    Well, personally (and others have other views, I'm sure) I deem framework "good" when I: 1) don't need documentation to use it, i.e. it is self-explanatory, and usage is obvious with no hidden surprises. If you need to read hundred doc pages before writing "HelloWorld", it is not good; 2) spend my time using framework, instead of fighting with it, trying to overcome shortcomings/bad design; 3) can use it the way I'd see feasible, and not the "only" way authors force you to go. For example, MFC is bound to Doc/View paradigm. As soon as you even think to try to go other way, you are penalized. I mean, it is still doable, but with much more efforts than it could be and should be. As for WinForms or WPF - they are very good if you use C# (or other .Net lang). If I'd go with C#, I'd jump on winForms, and there would be no question. Question is about C++ framework... For example, I'd say that Win32++ is close to ideal, with two exceptions. First one is minor - author uses same names as MFC, so you can't mix'n'match those two, but this is really minor. But second exception is very big, and is very same as U++ problem - who uses it? Very, very few people, so even though I like this one, it is of no use for my goal.

    Design and Architecture c++ learning delphi database performance

  • C++ GUI Framework
    K Kosta Cherry

    Well, I tried to explain my goals. For the needs of the project I can use anything available - Qt, Win32++, or even straight Win API - it'll all work out fine, as GUI that I need it very minor. But the goal is not just use some framework to create GUI, but learn it for good and then use in extensively on my next job(s), and not jumping on a new framework every (half)year. I'm already at the age when job should also bring fun, not just money. And Managed C++ is by no means "fun" - whoever designed it was really, really sick, and probably inspired by Brainf.ck language :) Basically, there is no beauty of C++ left in it, only "Managed" horror :(

    Design and Architecture c++ learning delphi database performance

  • C++ GUI Framework
    K Kosta Cherry

    Well, you are right to some extent - nobody can foresee a future. For example, if someone asked me same question six months ago, I'd say - go Qt. And then they blew up. On another hand, it's year 2012, and it amazes me that these is still no widespread good, "industry standard" C++ GUI framework. Or at least I don't know about the one. MFC/ATL is "industry standard" (on windows), but it is by no means "good". Qt was meeting these requirements for quite some time, but not anymore. So I'm kind of clueless at this moment. As for HTML5, for example - I can code it; I also know Java, C# and many other things. Yes, they are in demand, but, as I tried to explain, I can't make myself to have fun with them - not after you get with C++. Yes, for someone struggling to find at least some job I might look nitpicking and arrogant, but as long as I have choice, I'd like to stick to something that gives me sense of inner satisfaction and joy. Language-wise, it happend to be C++, so I'll try to ignore other things for as long as I can :)

    Design and Architecture c++ learning delphi database performance

  • C++ GUI Framework
    K Kosta Cherry

    Before I ask a question, I should explain why I'm asking it and what for, to avoid flame, as question is highly flamable. I'm in software development for 20+ years. I used to work with numerous (over 18) languages, many OSes, frameworks, platforms, etc. Over time I grew tired of learning some "new exciting tool/language/platform/you name it" just to have it disappear year or two later, or got superceeded with something else. I have only one life and don't want to waste it on learning "fashion" things that come and go before you even notice them. Besides, over time I grew to appreciate only two things - performance and "code beauty" (such as readability and maintainability). So, my by far preferred choice is C++. Yes, it is over 40 years old, but I bet it'll stay here for at least same amount of time. STL earned it's way into same league of "yes, we are here forever" (although I'm not big fan of it, but yes, it is well worth learning and sometimes even using :) it). And, or course, SQL. The new guy on a block is OpenCL, which was fighting with CUDA for quite some time now, and finally started to get into the same status as C++, STL and SQL. I want to make myself clear - this is my personal choice, and I'm not advocating anybody else to agree with me, I just want to explain the starting point for my question. I'm undertaking a new project right now with two goals in mind. First one is obvious - if I succeed, I wouldn't need to work for somebody else ever again :). Second goal is - if I'll fail, then at least I will learn something new to make me more marketable, as in "able to find a decent and fun job with high pay" :). And this is second goal that gives me headache right now. Major part of the project is "number crunching", so I'm fine with what I already know and have. But minor part of the project involves GUI, and that is where I was hoping to learn something new AND have value of that skill to be retainable for quite some time. I used to work with Delphi/VCL (which I deem as a very, very good attempt at being perfect framework), Powerbuilder (well, this was not quite a framework, but it was, well, not too bad, and for displaying large amounts of data it was the fastest thing I ever saw), and last few years I worked extensively with MFC/ATL (which I deem as ugliest thing ever invented), and some other libs/frameworks that are not even worth mentioning. So, I set myself on a search for a new GUI framework that "is here to stay". I code 99.99% of time for Windows, so I didn't care for other platfor

    Design and Architecture c++ learning delphi database performance

  • Special case of templates, pointers-to-members, inheritance - works in VC++ 2008, GCC 3.4.4, but fails in VC++ 2005
    K Kosta Cherry

    OK, question still remains, but I solved the problem by moving declaration of pointer-to-member this way:

    //#define PointerToMember(B) B::*
    #define PointerToMember(B)

    Two<true, S>::OneUsage<int S::*, &S::i> two;
    //Two<true, S>::OneUsage<int, 1> two;

    Pay attention to this line:

    Two<true, S>::OneUsage<int S::*, &S::i> two;

    Basically, instead of saying to template in the declaration that passed variable is of type pointer-to-member, I just make typename "C" to be pointer-to-int-member. Problem with this is that now I don't know the final type of variable "D", and if I will ever need it, I would need to pass it separately, i.e. adding one more template parameter. This variant compiles everywhere, but question still remains: what's wrong with previous one? It's more compact and straightforward...

    C / C++ / MFC help c++ wpf oop

  • Special case of templates, pointers-to-members, inheritance - works in VC++ 2008, GCC 3.4.4, but fails in VC++ 2005
    K Kosta Cherry

    Hi All, I'm hitting my head against the wall third day about the following code:

    //#define PointerToMember(B) B::*
    #define PointerToMember(B)

    template <bool A, typename B, typename C, C PointerToMember(B) D>
    class One
    {
    public:
    One() {};
    };

    template <typename B, typename C, C PointerToMember(B) D>
    class One<true, B, C, D> : public One<false, B, C, D>
    {
    public:
    One<true, B, C, D>() : One<false, B, C, D>() { };
    };

    template <bool A, typename B>
    struct Two
    {
    template <typename C, C PointerToMember(B) D>
    class OneUsage : public One<A, B, C, D> { };
    };

    template <typename B>
    struct Two<true, B> : public Two<false, B>
    {
    template <typename C, C PointerToMember(B) D>
    class OneUsage : public One<true, B, C, D> { };

    };

    struct S { int i;};

    int main()
    {
    //Two<true, S>::OneUsage<int, &S::i> two;
    Two<true, S>::OneUsage<int, 1> two;
    return 0;
    }

    With those two lines commented out, it compiles in all 3 compilers: GCC, VC++ 2008 and VC++ 2005. But, if instead of

    //#define PointerToMember(B) B::*
    #define PointerToMember(B)
    ...
    //Two<true, S>::OneUsage<int, &S::i> two;
    Two<true, S>::OneUsage<int, 1> two;

    you will make it this:

    #define PointerToMember(B) B::*
    //#define PointerToMember(B)
    ...
    Two<true, S>::OneUsage<int, &S::i> two;
    //Two<true, S>::OneUsage<int, 1> two;

    it still will compile in GCC and 2008, but will fail in 2005 with error: error C2955: 'Two<A,B>::OneUsage' : use of class template requires template argument list with [ A=true, B=S ] list4.cpp(30) : see declaration of 'Two<A,B>::OneUsage' with [ A=true, B=S ] error C2133: 'two' : unknown size error C2512: 'Two<A,B>::OneUsage' : no appropriate default constructor available with [ A=true, B=S ] Looks like VC++ 2005 compiler does not like usage of pointer-to-member type declaration when inheriting templates with partial specialization. Is it a bug of VC++ 2005, or I break some C++ standard, and other two compilers are just more forgiving? This code was taken from much more complex one just to show exact problem. Code compiled by both VC++ 2008 and GCC works with no issue and as

    C / C++ / MFC help c++ wpf oop

  • Network (?) question
    K Kosta Cherry

    Thank you for the hints! Based on them, I found this excellent basic description: http://www.wilsonmar.com/1loadbal.htm[^] Now looking for VRRP freeware on Windows :)

    IT & Infrastructure sysadmin question c++ com architecture

  • Network (?) question
    K Kosta Cherry

    Thank you, you understood correctly. First two possibilities are not good as when proxy server (or any other type of root server), or hardware server goes down, service gets interrupted for all clients - not just one set of them. Possibility three was the one that I considered, but first I wanted to check how "big boys" (i.e huge corporations) are doing that. Do they all have that unreliable schema with one entry point? It's kind of hard to believe. I must be missing something.

    IT & Infrastructure sysadmin question c++ com architecture

  • Network (?) question
    K Kosta Cherry

    Hi all, I have somewhat stupid question about network architecture. May be I'm even looking into the wrong direction, but I just don't know where else to start looking. I need a client to connect to "mysupercoolservice.com" at some port, and then server will start streaming data to the client. I understand, how it is done in case of one computer, and I worked a little with sockets. But I have no idea how to handle situation for many servers. I mean, when client connects, it is looking for IP or name of my service site, and provides specific port. This combination can point to only one NIC, right? But what I need is that when one server is already handling enough clients, then new client is connected to a different server. But client needs to know only one IP and port number! How this can be done? Load balancing (i.e. making decision WHICH server to connect), I do with my own software - that part I understand. I don't understand how to have client, that connects to particular IP/port, routed to the different server without closing client connection and reopening it with new IP/port combination. I did read about clusters, but there is always "head" server, that monitors usage. What if it goes down - other servers become useless? Sorry, I'm complete novice in network topology/logic, although have very good C++ experience. Thanks in advance for answers!

    IT & Infrastructure sysadmin question c++ com architecture

  • Please enlighten me on STL iterators and CriticalSection locking
    K Kosta Cherry

    I think I (almost) found answer to my own question. Here is code: #if _HAS_ITERATOR_DEBUGGING void _Orphan_range(pointer _First, pointer _Last) const { // orphan iterators within specified (inclusive) range _Lockit _Lock(_LOCK_DEBUG); const_iterator **_Pnext = (const_iterator **)&this->_Myfirstiter; while (*_Pnext != 0) if ((*_Pnext)->_Myptr < _First || _Last < (*_Pnext)->_Myptr) _Pnext = (const_iterator **)&(*_Pnext)->_Mynextiter; else { // orphan the iterator (*_Pnext)->_Mycont = 0; *_Pnext = (const_iterator *)(*_Pnext)->_Mynextiter; } } #endif /* _HAS_ITERATOR_DEBUGGING */ It's all over STL code, but it looks like locking happens only during 1) Debug Mode and 2) MultiTreaded application.

    ATL / WTL / STL c++ performance question

  • Please enlighten me on STL iterators and CriticalSection locking
    K Kosta Cherry

    I use STL at work, but "lazy" way, i.e. it works, and who cares about performance, right :)? So I know only basics about STL. Now I'm currently writing heavily multithreaded program for my own good. For the sake of fast development at this stage I opted to use STL. And then I noticed during debugging, that STL iterators call Critical Section locking, which causes a lot of slow down. I then delved (very briefly) into STL code and saw that they are really using CS for the iterators. I immediately dropped STL from the project, thanks to the fact that I use only arrays, not lists or maps, and there are plenty straight-forward-no-hidden-things implementations of templated arrays out there. But now I'm curious: when exactly STL iterators use CS locking? Is it for non-const iterators only? Is it for in-between-threads access? Or always? I'm too lazy and too busy to dive deep into STL code to check this, and it's not relevant to the project anymore, but out of curiosity it is very interesting, and might be useful for others who strive for performance and use STL. Thank you in advance! P.S. Forgot to mention: I use MS implementation of STL (VC++ 2005). SY- Kosta.

    ATL / WTL / STL c++ performance question

  • Performance question
    K Kosta Cherry

    Colin Angus Mackay wrote:

    here is insufficient information to give any reasonable answer. Anything would be pure guess work. You are best prototyping your situation and seeing which comes out top. Kosta Cherry wrote: select ~5000 records (by the key) for each object.

    I mean SQL like this: select * from mytable where ((timekey > X and timekey < Y) AND/OR some other conditions, but they all involve indexed columns only) The result brings up ~5000 (or so) rows. If all records are within several tables, I will run that query ~1000 times. If all records are within one table, I will add into WHERE additional condition like "objectID in (select objectID from other table where ....)", or may be just a join, or whatever other condition. The problem with modeling will be that selection from many tables will be done from multithreaded application, and I'm not sure how servers will react compared with single-threaded approach when all sits in one table and retrieved with one query; plus, those DB servers should be properly tuned for one approach or another. All of this involves a lot of modeling. I'm kind of leaning towards the "many tables" approach from the point of maintainability (where I can have each table on different table space or even different server).

    Colin Angus Mackay wrote:

    Kosta Cherry wrote: I have each object inside it's own table What do you mean by "object"?

    "Object" here is just named collection of millions of similar records - like, for example, file is collection of bytes, or picture is collection of pixels.

    Colin Angus Mackay wrote:

    Kosta Cherry wrote: I don't care about write performance. Have you considered using indexes rather than splitting up tables? (indexes slow down writes but can improve read performance if used correctly)

    Of course I did. I just don't know which way it'll work faster. On one hand, having all records in one table increases Btree+ index depth by 1-2 levels (depending on number of keys in the leaf), which increases seek time; on another hand, having records in different tables requires additional time for parsing (1000 queries instead of 1); so it's a hard to say what will be faster in the end.

    Database database mysql postgresql performance question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups