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
D

DQNOK

@DQNOK
About
Posts
114
Topics
11
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Extreme Artificial Intelligence
    D DQNOK

    Well it seems you're already pretty convinced of what "self awareness" is (you defined it for us in an earlier post), so I won't comment on that. What I found most compelling is your signature: "...every year find you a better .. woman." SWEET! A better (new?) woman every year! I might actually enjo NO WAIT, HONEY, I DIDN'T WRITE THAT. PUT THE BAT DOWN! OW. OW. OW.

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    Algorithms question

  • goto loops
    D DQNOK

    I just got through reading all the comments (as of the time I'm posting). Here's my 2 cents. I skipped formal religious training (ie degree in computer science from university -- taught by monks who are constrained to teach the latest C.S. fad or risk losing their jobs) and instead "squandered" my time at university studying math and science (my parents were so ashamed :(( ). Anyway, because of my secular education, I tend to be mostly agnostic when it comes to religious wars on subjects like: - use of goto - use of macros - procedural versus Object Oriented, versus Aspect Oriented programming - which language (Python, Java, C#, etc.) the angels in heaven speak - which language (Cobol, Fortran, Algol, etc.) the demons in hell speak. I once heard a man say to his deeply religous mother, "But mom, even Jesus drank wine", to which she responded "Yes, but I'd have thought better of Him if He hadn't!" Perhaps there are just times when the angels, in order to be understood by us mere mortals, stoop to vile "hell-speak" and use goto. At which point, we would have thought better of them if they hadn't... ;)

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    The Lounge csharp question

  • Y2.01K Bug [modified]
    D DQNOK

    I just encountered some code that fixed a Y2K issue with the following:

    decade = substring( my_YYDDD_DateString, 1,1 ) ;
    --return a YYYYDDD date string.
    if( decade = 0 ) then
    return "20" || my_YYDDD_DateString ;
    else
    return "19" || my_YYDDD_DateString ;

    HOLY MOLEY! They took a Y2K issue and fixed it by creating a Y2.01K issue. Given that the Fiscal Year where this code is used ends on Sep 30, they've got about 56 days to get it fixed! When the task to fix Y2K issues was given to programmers over a decade ago, I think most of us just assumed they would actually fix it; not just push it out one decade. It appears that the programmers that wrote this may have been paid by the line because they duplicated that code segment above throughout the code. A true "sliding window" would have been just as easy to implement, but then, they wouldn't have been able to cash-in on fixing the Y2.01K bug. Kind of scary. Get ready to get out your wallets!

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    modified on Wednesday, August 5, 2009 5:44 PM

    IT & Infrastructure help c++ html com

  • Records and Clusters [modified]
    D DQNOK

    A second response: Have you noticed that Mix now sells a Win32 version of their database toolchest? I don't suppose you've compared their implementation against yours, have you? I know nothing except what they've posted on their web site.

    David

    Algorithms c++ html com data-structures performance

  • Records and Clusters [modified]
    D DQNOK

    Thanks for remembering me. I looked into it and decided you were right; using the binary tree was the wrong approach. Binary trees just do too much memory thrashing. I also got off on a really hot project and had to set it aside for a while. I downloaded a couple of free BTree libraries, but I'm never happy with stuff I get from outside. They will have been developed with their own support libraries, which usually conflict with mine, or they are missing features I want, or are bloated with features I don't want, etc. I really just wanted an in-memory index, without the burden of a disk-based system. However, I really should consider a product that has disk-based storage in case I want to expand later on. I'm still interested, just haven't taken "the plunge" yet. It's not the money; it's the time committment in learning a new system and adapting all my stuff to their way of doing things. I'm just responding to your post without having gone back and reviewed everything that was said to this point. I'm going to do that, plus, if you have anything else new to add, I'd be glad to hear it. Perhaps I should just go ahead and buy the source...

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    Algorithms c++ html com data-structures performance

  • Records and Clusters [modified]
    D DQNOK

    This discussion has sent me looking into B+trees. Some of the little code I've found looks ridiculously simple (by comparison to my BalBinaryTree implementation). I have no idea of speed comparisons, but it makes sense that they would be fast or else RDBMS's wouldn't use them. Plus it seems they might actually be smaller since every record in my tree system carries 12 bytes of overhead. Yes, the mix source is still available, but it sounds like the right source to have is Mix's (which of course requires a small $ outlay) plus your modifications. My (junk) e-mail address is davidlqualls@yahoo.com I don't check it every day; and it fills up with garbage pretty fast, but if you'll put "B+Tree" in the subject line, I'll be looking for it. Thanks. David

    Algorithms c++ html com data-structures performance

  • Records and Clusters [modified]
    D DQNOK

    Member 4194593 wrote:

    Have you ever considered B+ trees as implemented by "The C Database Tool Chest", Mix Software.

    No, I hadn't; but I am familiar with Mix, and have used both their Power C compiler and their C utilities toolchest. I'll have to back-up and reconsider whether this would be a good approach to my end goal (which was NOT to rewrite the balanced binary tree algorithms). I originally rolled my own balanced binary tree routines because the ones I found on the web didn't support duplicate keys, nor multi-threading. The clusters were an after-thought (actually, they came about from a "Hey, I can use the tree structure instead of yet-another-roll-my-own exotic structure -- IF I can speed them up sufficiently -- perhaps reclustering would do it). Thanks for the thoughts.

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    Algorithms c++ html com data-structures performance

  • Records and Clusters [modified]
    D DQNOK

    For many varied reasons, I decided to write my own balanced binary tree library. One feature of my library that I haven't seen in other freely available libraries is "clusters", and a "recluster" function. The problem that I am attacking is that as elements are randomly added to the tree, the tree rotations that automatically happen to keep the tree balanced tend to spread the edge pointers all over the place. The end result is that in a large tree, a typical traversal can require reading nodes from all over physical memory (or disk pages): a very inefficient use of cache. By clustering several subtree "near the root nodes" together in physical memory, tree traversals can be sped-up significantly by keeping nodes that always get visited near one another within physical memory (or on the same disk page). For example, in a properly clustered tree, with clusters large enough to hold 4 levels of records (1+2+4+8 = 15 records), a tree of height 16 (>45000 records) can be traversed in only 4 cluster reads instead of 16 reads that might be required of a non-clustered tree. What I don't know is a good way to measure how "out-of-cluster" a tree is. I'd like to be able to determine when a tree needs to be reclustered. I'm sure there is good theory out there for this; and the idea doesn't seem to be that difficult, but I haven't run onto the solution yet. I've spent a little bit of time googling for a method, and probably a couple of hours thinking about it. Nothing yet. Any ideas or helpful links?

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    modified on Wednesday, November 5, 2008 11:33 AM

    Algorithms c++ html com data-structures performance

  • Convert double to fixed point integer format - hard way versus easy way...
    D DQNOK

    How is the static_cast better than a normal cast in this case?

    David

    The Weird and The Wonderful c++ question

  • Difference b/w Unions and Structures...
    D DQNOK

    Alan Balkany wrote:

    each one starts in the byte after the previous one ends.

    Too specific to be the right answer for this newbie. One poster said "conceptually" the sizes of the members sum, which is correct *CONCEPTUALLY*. We should probably point out to the original poster that in a structure, the compiler is free to add padding after ANY member (including the last member) to insure the members align correctly. That is, a structure may contain unused bytes that are there only for alignment.

    struct example{
       char c;  //one byte?
       long l;  //four bytes?
    };
    printf( "sizeof(example) = %d", sizeof(example) );
    

    In most compilers, this will NOT print "sizeof(example) = 5" as might be expected, since the compiler must put padding after c to insure that l aligns properly. In most modern compilers this will likely print "sizeof(example) = 8".

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    C / C++ / MFC question

  • How to compare stderr to stdout
    D DQNOK

    Nibu babu thomas wrote:

    Does GetStdHandle() help?

    From reading the MSDN site, I thought it would; but it doesn't do what I thought.

       HANDLE  stderrHndl = GetStdHandle(STD_ERROR_HANDLE);
       HANDLE  stdoutHndl = GetStdHandle(STD_OUTPUT_HANDLE);
    
    ...
    (very incomplete!)
    
       vfprintf( stderr, msg, args );
    
       if( stderrHndl == stdoutHndl ) //still ALWAYS tests FALSE
          goto logprint; //skip printing to stdout
    
       vfprintf( stdout, msg, args );
    logprint:
    

    Because the stderrHndl == stdoutHndl is always evaluating to FALSE, I'm still double printing to the console.

    David

    C / C++ / MFC c++ html com tutorial question

  • How to compare stderr to stdout
    D DQNOK

    Nibu babu thomas wrote:

    Does GetStdHandle() help?

    I'll look into it. Thanks for the idea.

    David

    C / C++ / MFC c++ html com tutorial question

  • How to compare stderr to stdout
    D DQNOK

    I like that idea. But this needs to be general. It's an "alert" library (a very minature logging library) that needs to detect on its own whether stderr has already been redirected. Key idea: *auto-detect* where stderr is outputting to, and if it's going to stdout, skip over the requirement to write to stderr.

       vprintf( alertMsg, msgArgs );             //print to stdout
       if( stdout != stderr )  
          vfprintf( stderr, alertMsg, msgArgs ); //print to stderr
     //otherwise, already printed to stderr.  Just move on.
       ...
    

    (Note: code is not complete; it needs some complicating va_end and va_starts in there to make it work correctly. Don't use it as a model!)

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    C / C++ / MFC c++ html com tutorial question

  • How to compare stderr to stdout
    D DQNOK

    DavidCrow wrote:

    What about: if (&stdout == &stderr)

    That won't compile under Visual C++ The standard says that stdout and stderr are macros that evaluate to FILE pointer rvalues. Taking the address them seems suspicious from the outset...

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    C / C++ / MFC c++ html com tutorial question

  • 'LONG' to 'int' [modified]
    D DQNOK

    It should work even as a type long (I'm not familiar with type LONG: if it's a composite type, then it won't work). Any reason you can't just cast it to int at the point you are actually using it within the loop? This should work (provided x is not a composite type)

    for( x = someval; x < someotherval; x++ )
    {
       ...
       i = (int)x; //cast x to int where it's actually needed.
    }
    

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    C / C++ / MFC

  • How to compare stderr to stdout
    D DQNOK

    In a console app, I want to be able to test whether stdout and stderr are both printing to the screen. My output is messy unless I get it right (I'm printing to both stdout, and to stderr, and if they both happen to be the screen, I get two copies; I only want one copy on the screen). A line like if( stdout == stderr ) always tests false under all the Windows compilers I've tried, so I get the duplication I'm trying to avoid. Any ideas?

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    C / C++ / MFC c++ html com tutorial question

  • Error using GetPrivateProfileString and GetPrivateProfileSectionNames
    D DQNOK

    I've inherited a large VB6 project (with zero chance of moving it to VB.NET) that I am slowly refactoring, beginning with reading the .ini files. Never mind the way it currently works, I just want to read all the section names, then within each section name, read all the keys and values. According to the documentation on MSDN, this should be simple. The GetPrivateProfileSectionNames function should give me the section names, then GetPrivateProfileString (with a null for key-name) should give me the list of key/value pairs within the specified section. But they're not working. When the GetPrivateProfileSectionNames wouldn't work, I tried switching to GetPrivateProfileString and passing it a null for the section name (which according to MSDN should do basically the same thing as GetPrivateProfileSectionNames). Again, no luck. I could copy all the declarations and usages here (and will if I need to), but was hoping someone else may have experienced the same thing and already recognizes the symptoms and knows the answer. Any help appreciated.

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    Visual Basic help csharp c++ html

  • Newton's first order numerical method.
    D DQNOK

    The numerical recipes book(s) has been a God-send for many of us. It was originally for Fortran, then translated to (a rather clunky, but functional) C. The really great thing is that they do a good job of explaining the algorithms. I have, for the most part, just used their explanations and written my own code. Here's a link to their older versions that you can read on-line. http://www.nrbook.com/a/[^] You can also find their most recent versions at www.nr.com The book will explain the Newton method, and have examples of it's use.

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    Algorithms tutorial com question

  • Assigning random lives: an algorithm
    D DQNOK

    DQNOK wrote:

    Do you know the algorithm for using the rand() function (which generates a uniform PDF) to generate values within a specified PDF?

    I answered my own question. For a PDF called 'y(x)' (where x is the random varaible), and a computer library function rand() that returns a random value in the range [0, 1) from a uniform PDF, we seek to map rand's return value (call it rx) to the correct x. Effectively, we are looking for x such that the area under the curve y(x) LEFT OF x is equal to the area under the uniform PDF left of rx. But since rand produces values within the unit interval [0,1), rx IS the area under the curve left of rx. So, we seek x such that: rx = integral from -infinity to x of y(x) Exactly HOW we evaluate the integral (i.e. solve for x) is an implementation detail that depends on how y(x) is defined. If the integral is already given via a formula, we just use a standard non-linear scalar solver, like a Newton-Raphson. It not, then perhaps I would just use a stepping approach, something like:ndx = getBestStartingIndex(rx); x = X_STARTS[ndx]; // X_STARTS[ndx] <= rx < X_STARTS[ndx+1] area = AREAS[ndx]; // precomputed areas based on x. old_y = y(x); while( area < rx ) { x += dx; new_y = y(x); area += dx * (old_y + new_y)/2 ; //trapezoid rule old_y = new_y; } return x;
    Which can be polished for better precision, time-performance etc.

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    modified on Thursday, April 17, 2008 9:28 AM

    Algorithms css algorithms help tutorial question

  • Assigning random lives: an algorithm
    D DQNOK

    Do you know the algorithm for using the rand() function (which generates a uniform PDF) to generate values within a specified PDF? I've thought thru it before, but didn't write it down. Also, without having a parameterized function for the PDF (I doubt it's even possible to come up with a formula for a left-truncated PDF like we're talking about -- plus, it would change for each item) this seems hard. UNLESS! I don't model the PDF with a parameterized function, and instead model it via a table of values obtained from the original PDF formula. That should be easy enough to normalize by just numerically integrating the remainder of the curve. Well, maybe this won't be so hard. (Famous last words...)

    David --------- Empirical studies indicate that 20% of the people drink 80% of the beer. With C++ developers, the rule is that 80% of the developers understand at most 20% of the language. It is not the same 20% for different people, so don't count on them to understand each other's code. http://yosefk.com/c++fqa/picture.html#fqa-6.6 ---------

    Algorithms css algorithms help tutorial 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