Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2004

Tip: Looking for answers? Try searching our database.

lstrlen and strlen

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Abubakar - 22 May 2004 16:32 GMT
Hi all,
I noticed that the lstrlen is *much* slower than strlen function. Why is it
so and does that mean i should never use the lstrlen, and if not than why is
it there anyway?

Regards,

- Abubakar.
Julie - 22 May 2004 16:51 GMT
> Hi all,
> I noticed that the lstrlen is *much* slower than strlen function. Why is it
[quoted text clipped - 4 lines]
>
>  - Abubakar.

lstrlen is mostly there for historical reasons.  Back in the days of 16-bit
Windows, most applications were built using the small or medium memory models
in the interest of increasing performance and reducing size (in those memory
models, the default pointer size was 16 bits, which lead to problems for
strings (or other memory blocks) that were greater than 64KB or happened to
span a 64K boundary).  lstrlen was added which used 32-bit pointers (prototype
and internally), and therefore could operate on large strings and strings that
spanned boundaries.  lstrlen was later updated to perform additional validation
on the parameters and would fail rather than crash Windows on bad parameters.

Additionally, lstrlen is a Windows function (dynamic link) where strlen is a
library function (static link, unless you link in the CRT as a DLL).  Static
linked functions will _always_ be faster than than an identical counterpart
that is dynamically linked.

lstrlen is also actually a macro to lstrlena or lstrlenw, which maps to the
appropriate function depending on whether or not you are building to Unicode or
not.  strlen is always single-byte (SBCS), so if you want similar
functionality, you should get in the habit of using the tchar string functions
declared in tchar.h.

So, unless you have a specific need to use lstrlen (it sounds like you don't),
get in the habit of using the tchar version _tcslen().

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.