473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

lstrlen and strlen

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.
Nov 17 '05 #1
1 5721
Abubakar wrote:

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.


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().
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: sugaray | last post by:
hi, it just came up my mind that since we can get the length of any given string literal S with 'sizeof S-1', so, what's the merit of library function strlen()'s existence ? thanx in advance for...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
33
by: apropo | last post by:
what is wrong with this code? someone told me there is a BAD practice with that strlen in the for loop, but i don't get it exactly. Could anyone explain me in plain english,please? char...
66
by: roy | last post by:
Hi, I was wondering how strlen is implemented. What if the input string doesn't have a null terminator, namely the '\0'? Thanks a lot Roy
83
by: rahul8143 | last post by:
hello, what is difference between sizeof("abcd") and strlen("abcd")? why both functions gives different output when applied to same string "abcd". I tried following example for that. #include...
10
by: danielesalatti | last post by:
Hello!! I'm studying c++ and I'm trying to get a little piece of code working, but I'm getting a segfault with strlen here: void tabhash::set (url *U) { uint hash = U->hashCode(); char* url =...
2
by: Chris | last post by:
Hi there, I have been reading in this group for a while really enjoy this pool of infinite c wisdom. :) Anyway, I have question now. I have this little piece of code that is giving me a...
53
by: ¬a\\/b | last post by:
strlen is wrong because can not report if there is some error e.g. char *a; and "a" point to an array of size=size_t max that has no 0 in it
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.