When you ask how long it is, keep in mind that some guys may exaggerate their answer

by Michael S. Kaplan, published on 2006/11/28 14:30 -05:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/11/28/1166834.aspx

A common question someone might have if they need to allocate a buffer is How much space do I need to allocate?

The question seems simple enough to ask, right?

Of course there are two different possible answers to the question when one is dealing with the non-Unicode versions of functions:

Now the hint I gave above about all of the extra work that the NLS API does is the answer to the obvious question people ask about why they have to put up with getting an estimated answer rather the actual answer -- there is a performance hit to that extra effort placed!

There are also plenty of people (like the SQL Server team) that hate the NLS "call twice" semantic due to the performance issue and the fact that we allocate. They prefer to use their own buffers and just call us once each time.

So clearly these two models each have a place in Windows (one is faster and less memory fragmenting, the other is more accurate), though admittedly the documentation could perhaps be clearer in some cases about which is which....

The rules are not always totally consistent, either; even within NLS, there is the NormalizeString function, which estimates (and sometimes in some extreme cases even returns a buffer size that is too small, a factoid that causes lots of grief for FoldString function in Vista, which guarantees exact results even though for MAP_FOLDCZONE, MAP_PRECOMPOSED, and MAP_COMPOSITE it wraps NormalizeString).

Which just goes to show you that as in life you have to keep in mind when people might exaggerate when you ask them how long something is for reasons that they may or may not choose to make entirely clear to the people asking. :-)


This post brought to you by 𐨌 (U+10a0c, a.k.a. KHAROSHTI VOWEL LENGTH MARK)

# A.C. on 29 Nov 2006 12:32 AM:

Your analogy breaks down quickly, Michael. Guys who exaggerate their "length" don't do it out of laziness.

# Michael S. Kaplan on 29 Nov 2006 12:55 AM:

True enough, A.C. But they sometimes do it out of performance anxiety. So I think my analogy may still be intact (though I admit it hadn't occurred to me before)....

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day