-
Content Count
3586 -
Joined
-
Last visited
-
Days Won
176
Everything posted by David Heffernan
-
Remove non-utf8 characters from a utf8 string
David Heffernan replied to borni69's topic in Algorithms, Data Structures and Class Design
We've all done it. It never works out. -
Remove non-utf8 characters from a utf8 string
David Heffernan replied to borni69's topic in Algorithms, Data Structures and Class Design
There's a lot of noise in here. It seems you don't really understand where these characters are coming from and are in trial and error programming mode. The advice from the wise heads here is to understand what is going on, and then work out how to tackle it. You don't seem to want to heed that advice. That's fine, it's your choice. But we don't need a blow by blow account of your trial and error coding. That's only meaningful to you. -
Is variable value kept after For.. in ... do loop?
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
REMOVED, sorry, was dupe -
Is variable value kept after For.. in ... do loop?
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
Yes that is correct. My argument stands. Copying the full record into a local is only expensive (compared to reading a value from the record in-situ in the array) if the record is large. For a small record, copying a handful of bytes costs no more than reading even a single byte. I'm arguing against your claim that there would be a performance hit using a for in loop even for small records. For large records there will be a hit. Not for small records. -
Is variable value kept after For.. in ... do loop?
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
No. Because when you iterate over an array, you typically don't read all of the content of each item. Imagine that all you do is look inside each record for an integer ID. If the record is huge, then you can just read a single integer, and move on, if using a classic for loop with an array of record. But if you use a for in loop you have to copy the entire record before reading the single integer ID. That's wasteful. In the case of a smaller record, let's say small enough to fit into a cache line, then reading an integer from the record has the essentially same cost as copying the entire record and then picking out the integer. So the trade off depends hugely on the size of the record, and what proportion of it you actually need to access. -
Remove non-utf8 characters from a utf8 string
David Heffernan replied to borni69's topic in Algorithms, Data Structures and Class Design
Better hope that there are no line breaks ..... -
Is variable value kept after For.. in ... do loop?
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
Why would there be an issue for small records? Presumably you are iterating over the array because you want to look at the content of the record. For a small enough record, there won't be any difference in perf between reading a field and copying the entire record. -
Remove non-utf8 characters from a utf8 string
David Heffernan replied to borni69's topic in Algorithms, Data Structures and Class Design
Your problem is not how to remove characters, it is to work out what characters are to be removed. As is so often the case, the hardest part of any programming tasks is determining the correct specification. -
Is variable value kept after For.. in ... do loop?
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
The hardware is designed to handle indexed access efficiently. I've seen plenty of cases where incrementing a pointer inside the loop is slower. After all, you have an extra variable that needs to be incremented. Hard to see why that would be faster. No. The memory access pattern is identical. It's just a sequential pass across the array. -
Remove non-utf8 characters from a utf8 string
David Heffernan replied to borni69's topic in Algorithms, Data Structures and Class Design
The two 0b characters are valid UTF-8 characters. They are this character: https://www.fileformat.info/info/unicode/char/000b/index.htm What you need to do is decide exactly what your specification is. The question you have asked doesn't seem to match the example you have provided. -
Is variable value kept after For.. in ... do loop?
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
Not necessarily. And in any case, if you wanted performance, you'd not have chosen Delphi. -
Is variable value kept after For.. in ... do loop?
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
This is why I always implement my enumerators as records so that they can be automatically allocated. Will it? Faster than array indexing? That seems to be something of a myth in my experience. -
Is variable value kept after For.. in ... do loop?
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
Correct. -
Is variable value kept after For.. in ... do loop?
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
Loop variables are assigned using assignment semantics. That's all you need to know. -
Is variable value kept after For.. in ... do loop?
David Heffernan replied to Mike Torrettinni's topic in RTL and Delphi Object Pascal
It's the same issue for both types of for loops. The value of the loop variable is undefined if the for loop terminates normally. In your case that corresponds to the condition never having been met. Unfortunately though, whilst you are aware that there is an issue here, you have not correctly understood what the issue is. That reasoning is incorrect. The loop variable i does not change in case of a normal termination, e.g. the break in your code. Before you consider for in loops I recommend that you correct your misunderstanding of for loops. Executive summary. There is an issue with for loops of both kind. It is the same issue for both kind of for loop. But the issue is not what you have described. -
Remove non-utf8 characters from a utf8 string
David Heffernan replied to borni69's topic in Algorithms, Data Structures and Class Design
Define what you mean by a non UTF8 character, remembering that this is a variable width encoding. -
Getting Stream read error on really simple program
David Heffernan replied to Mr. Daniel's topic in RTL and Delphi Object Pascal
Why are you cross posting? https://stackoverflow.com/questions/64010603/delphi-getting-stream-read-error-on-really-simple-program At every site where you cross post, potentially different people will provide you the answer. Which means that more people than necessary spend time on this. As a broad rule, people who provide this sort of help don't appreciate this kind of behaviour.- 5 replies
-
- stream
- tmemorystream
-
(and 1 more)
Tagged with:
-
string helpers question
David Heffernan replied to David Schwartz's topic in RTL and Delphi Object Pascal
DELETED: because it was nonsense -
Help needed. Re-raising exception gives AV.
David Heffernan replied to a topic in RTL and Delphi Object Pascal
This is the correct way to do this. It works fine. The problem is elsewhere. Don't create and raise a new exception. -
Blocking the Windows Screen Saver in Delphi
David Heffernan replied to dummzeuch's topic in Tips / Blogs / Tutorials / Videos
Packing does make a difference here. It may not change the layout, but it changes the alignment of the type. -
Blocking the Windows Screen Saver in Delphi
David Heffernan replied to dummzeuch's topic in Tips / Blogs / Tutorials / Videos
No it shouldn't be declared as packed. The structure, as is invariably the case for Windows structures, should be aligned. -
Best way to prevent multiple instances? Mutex not working
David Heffernan replied to bilbo221's topic in VCL
Nobody can diagnose the problem without seeing your code. Once you show us a minimal complete reproduction then it will be straightforward to explain the behaviour of your program. -
Generics: Classes vs Records - Differences in use
David Heffernan replied to Lars Fosdal's topic in Algorithms, Data Structures and Class Design
That trade off depends on the size of the record. For small records then performance is better if the items are stored directly in a contiguous array. -
New feature request: Open dfm as Text if malformed (vote if care)
David Heffernan replied to Tommi Prami's topic in Delphi IDE and APIs
OK, this is making more sense to me, and I can better appreciate the inconvenience. -
New feature request: Open dfm as Text if malformed (vote if care)
David Heffernan replied to Tommi Prami's topic in Delphi IDE and APIs
Maybe. I guess I might not be encountering the problem regularly. You must be facing it very regularly I guess. Isn't that a different issue?