-
Content Count
3586 -
Joined
-
Last visited
-
Days Won
176
Everything posted by David Heffernan
-
Why are you calling SetupDiGetDeviceProperty?
-
64 bit shift operations?
David Heffernan replied to A.M. Hoornweg's topic in RTL and Delphi Object Pascal
Imagine if we could specify the type of a literal ........ -
It depends. Get XP and try it.
-
This is it then isn't it. What's in the real program that causes the misbehaviour?
-
I don't experience this in my program. Can it be reproduced?
-
This should just work. The real question is why your modal message box is not on top. You should try to work that out.
-
Counting newlines in a huge string in parallel: improving Parallel.For())
David Heffernan replied to Gerben Abbink's topic in OmniThreadLibrary
No. The scheduler will put the tasks onto different threads for you. No. It means that the main thread is doing nothing, but since there are as many worker threads as cores, the CPU will be fully busy. No. Looking at your code, I guess you need to generalise it to work with an arbitrary number of tasks. This will require you to use some arrays in place of variables named 1, 2, 3, etc. It also looks like you are doing floating point division and I'm not convinced that you will count every single character, and also that you won't count some characters twice. I think you need to be more precise about the bounds of each task's work. -
FreeAndNil() - The Great Delphi Developer Debate
David Heffernan replied to AlexBelo's topic in Tips / Blogs / Tutorials / Videos
Your argument about intent is the closest that I have ever seen to a cogent argument on this subject. But I still don't buy it. In your argument, if you see code that sets references to nil then that indicates this "optional lifetime" pattern, for the sake of inventing a name. And your point is that if you set the reference to nil every time you destroy an instance, then you can't distinguish the optional lifetime pattern from the two more common lifetime patterns, let's call them "owned lifetime" where the object is destroyed in its owner's destructor, and "local variable lifetime" where the object is created and destroyed in a local method, and the reference is a local variable. The thing is though, when you see FAN in owned lifetime and local variable lifetime, it's unmistakeable what the lifetime is. You never think, oh, I wonder if this might be optional lifetime. That's why I don't buy the argument, and why I've never experienced the issues you describe. What I have experienced though is the pain of using a stale reference. That pain is eased if the reference is nil. And yes, we can use debug MM to write over memory when an object is destroyed, but I don't want that to happen in my release builds. And sometimes bugs only emerge in release builds. -
FreeAndNil() - The Great Delphi Developer Debate
David Heffernan replied to AlexBelo's topic in Tips / Blogs / Tutorials / Videos
True. But then I've never made that claim. -
FreeAndNil() - The Great Delphi Developer Debate
David Heffernan replied to AlexBelo's topic in Tips / Blogs / Tutorials / Videos
My code uses FAN rather than free as a rule, and I don't recognise the problem you describe. That's my practical experience. -
FreeAndNil() - The Great Delphi Developer Debate
David Heffernan replied to AlexBelo's topic in Tips / Blogs / Tutorials / Videos
Wrong solution. Right solution is to learn what you don't know how to do. No shortcut. Certainly not by just saying "use interfaces". -
FreeAndNil() - The Great Delphi Developer Debate
David Heffernan replied to AlexBelo's topic in Tips / Blogs / Tutorials / Videos
This makes no sense at all. If you instead use Free and retain a stale reference to a destroyed object, then other code simply cannot know that the reference is stale. There are two main scenarios. Object destroyed by owner, either from another instance's destructor, or in a method with try finally lifetime. FAN is just a debugging guard against use after free. Or a reference to an instance whose lifetime is dynamic. Perhaps created and destroyed multiple times by its owner. Then nil is used to indicate the state that the object is currently not in existence. It seems bizarre to me that anybody could advocate carrying around stale pointers. -
FreeAndNil() - The Great Delphi Developer Debate
David Heffernan replied to AlexBelo's topic in Tips / Blogs / Tutorials / Videos
As you say, that's a problem with the developer rather than the function itself. I personally use FAN everywhere and my debug builds use FastMM with all bells and whistles. There aren't downsides to using FAN and it does make it easier to catch some defects. -
FreeAndNil() - The Great Delphi Developer Debate
David Heffernan replied to AlexBelo's topic in Tips / Blogs / Tutorials / Videos
You fix the bug, which is nothing to do with FAN. That's my point. -
FreeAndNil() - The Great Delphi Developer Debate
David Heffernan replied to AlexBelo's topic in Tips / Blogs / Tutorials / Videos
No it doesn't. How else are you going to allow constructors to raise exceptions? -
FreeAndNil() - The Great Delphi Developer Debate
David Heffernan replied to AlexBelo's topic in Tips / Blogs / Tutorials / Videos
Yeah, because delphi is so fast! But also, I doubt you could find a real program that would have a measurable performance hit even if the ref was set to nil always. -
FreeAndNil() - The Great Delphi Developer Debate
David Heffernan replied to AlexBelo's topic in Tips / Blogs / Tutorials / Videos
Amazing that there's anybody left that doesn't know that Free does the nil check itself. -
FreeAndNil() - The Great Delphi Developer Debate
David Heffernan replied to AlexBelo's topic in Tips / Blogs / Tutorials / Videos
That's a bug to use that reference, so this issue can safely be ignored with regards FAN. -
As an aside, even in Delphi there is no such need. You can write 'first line'#13#10'second line' And even then, concatenation of literals is performed by the compiler, so the above code would result in the same codegen as 'first line' + #13#10 + 'second line' Finally, it is usually preferable to use sLineBreak rather than #13#10 so that your code is more expressive, and platform independent.
-
Left side cannot be assigned to
David Heffernan replied to AlanScottAgain's topic in RTL and Delphi Object Pascal
So instead of code like obj.foo := obj.bar + 10; you prefer obj.setFoo(obj.getBar() + 10); or perhaps obj.setFoo(obj.getBar + 10); (note that I personally am not keen on being able to call a function without the parens because it leads to ambiguity for type inference) -
Left side cannot be assigned to
David Heffernan replied to AlanScottAgain's topic in RTL and Delphi Object Pascal
These two statements appear in conflict with each other. Advocacy for using getter/setter methods directly, flies in the face of criticism that properties can't be passed as var or out params. Neither can methods. -
Perhaps the data module isn't being destroyed. If you showed a minimal reproduction then we'd be able to tell.
-
The latter. If you include this gpl licensed component then that propagates.
-
TStringHelper.IndexOfAny( array of string, ...): Why is this private ?
David Heffernan replied to Rollo62's topic in RTL and Delphi Object Pascal
There are times when this is desirable. It's a big weakness in my view that the type of a literal can be ambiguous. -
Same for integers, right? We don't feel compelled to store pointers to integers in arrays very commonly, do we.