Recent

Author Topic: Reference counting plz?  (Read 55837 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Reference counting plz?
« Reply #75 on: April 17, 2014, 02:46:17 pm »
Move your test to a procedure and then do

 
Code: [Select]
coinitialize(nil);
  benchmarkproc;
  couninitialize(nil);

Thanks for suggestion. Tried it. Memory usage increased by 1 kilobyte. I doubt though that it got attached to com interface instance, perhaps it was allocated globally. In terms of speed, however, no difference at all. Note that I do not measure time spent on class instance construction, only assignment

Thanks for testing. I just remembered that sometimes that would influence COM related issues (IIRC it is the per thread init of COM).

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Reference counting plz?
« Reply #76 on: April 17, 2014, 03:24:06 pm »
Then the compiler will not touch reference count for s.
Compiler skips reference counting for const arguments. Take a look at this article plz: http://www.freepascal.org/docs-html/ref/refsu63.html
That's my point.
You can't say "there's no impact" if you don't do the actual reference counting (by passing an interface as const).

What's the assembler for TestCOM procedure (with and without const)?


hinst

  • Sr. Member
  • ****
  • Posts: 303
Re: Reference counting plz?
« Reply #77 on: April 17, 2014, 08:39:19 pm »
In my test I have
Code: [Select]
procedure TestCOM(const aCom: IUnknown);
var
  b: IUnknown;
begin
  b := aCom;  // <- this assignment
So it should work as expected; produce one _AddRef call and one _Release call.
Too late to escape fate

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Reference counting plz?
« Reply #78 on: April 17, 2014, 09:20:21 pm »
ah yes... sorry, I missed that.

BeniBela

  • Hero Member
  • *****
  • Posts: 905
    • homepage
Re: Reference counting plz?
« Reply #79 on: April 17, 2014, 11:57:57 pm »
That is kind of irrelevant. Ref counting is ref counting, ofc it has around the same speed if implemented manually and via COM object.

The real issue is that with interfaces it is known which method is called during compile time, and has to be looked up during run-time. Especially since that breaks inlining

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Reference counting plz?
« Reply #80 on: April 18, 2014, 12:47:03 am »
Actually, ref counting by hand, can produce faster code.

If the compiler adds recounting (for local var), the compiler always assumes the procedure could be exited by exception.
Therefore the compiler inserts an "try finally" too.

If you add ref counting by hand, you may know that there can not be an exception, and you can skip the try finally.

So you save the try finally time.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Reference counting plz?
« Reply #81 on: April 18, 2014, 09:22:39 am »
Actually, ref counting by hand, can produce faster code.

If the compiler adds recounting (for local var), the compiler always assumes the procedure could be exited by exception.
Therefore the compiler inserts an "try finally" too.

If you add ref counting by hand, you may know that there can not be an exception, and you can skip the try finally.

So you save the try finally time.

Or just use {$implicitexceptions off}  O:-)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Reference counting plz?
« Reply #82 on: April 18, 2014, 11:09:43 am »
Or just use {$implicitexceptions off}  O:-)

 :o :-[ :'( :-*
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

hinst

  • Sr. Member
  • ****
  • Posts: 303
Re: Reference counting plz?
« Reply #83 on: September 08, 2014, 10:50:17 am »
will we ever have reference counting for user types in FPC? ever? this is long overdue. seriously. Of all FPC flaws, this one is the most annoying. FPC has reference counting for interfaces, strings and dyn arrays, but not for user types. It just feels wrong. Like it teases me

is there a way to make this work? some hack? anything?
Too late to escape fate

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Reference counting plz?
« Reply #84 on: September 08, 2014, 11:21:02 am »
will we ever have reference counting for user types in FPC? ever?

Not that I know.

Quote
this is long overdue. seriously.

That is purely opinion (and IMHO an ill-informed one)

Quote
Of all FPC flaws, this one is the most annoying. FPC has reference counting for interfaces, strings and dyn arrays, but not for user types.

This has been discussed umpteen times already, please look up all discussions that reference this and/or GC. Ref counting is hard for cases where types can nest and cause cycles. The current types don't nest ref counted entities

Quote
is there a way to make this work? some hack? anything?

No, it is fundamental. and not desirable in the first place. Automatic memory management needs to be designed into the language, not bolted on. 

Probably if you'd try that, you'd get something like Remobjects Oxygene.

hinst

  • Sr. Member
  • ****
  • Posts: 303
Re: Reference counting plz?
« Reply #85 on: September 08, 2014, 11:34:46 am »
Well it works for interface types, nested or not nested it does not matter at all; in FPC one can nest interface fields 100 levels deep, and still they all will be released appropriately when no longer in scope. Problems arise when there are circular references; but I am not asking for some sophisticated algorithm which would detect circular references, I just want reference counting enabled for class types.

Unfortunately I don't have money for Oxygene

What I am saying is that reference counting is already here. It is fully implemented for interfaces in FPC. I just want it enabled for class types because 99% of code is about class types, not interfaces
Too late to escape fate

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Reference counting plz?
« Reply #86 on: September 08, 2014, 11:50:01 am »
1. You're welcome to fork. As you must have realized by now if you read all those discussions, current developers simply do not think it is worth it to go that way. You obviously disagree but you won't change people's minds.
2. IIRC, the Oxygene command line compiler is/was free.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Reference counting plz?
« Reply #87 on: September 08, 2014, 01:25:25 pm »
Well it works for interface types, nested or not nested it does not matter at all; in FPC one can nest interface fields 100 levels deep,

No. Interfaces can't have fields. You can nest interfaces in objects, but not interfaces in interfaces. And objects are not refcounted.

Quote
Unfortunately I don't have money for Oxygene

Keep saving.

Quote
What I am saying is that reference counting is already here. It is fully implemented for interfaces in FPC. I just want it enabled for class types because 99% of code is about class types, not interfaces

Not possible. Personally, I would go for full Boehm GC in that case. That is also uncharted territory, but at least well known.  Trouble is that it has been proposed many times, but nobody really took the time to research it. And it is free! :-)

hinst

  • Sr. Member
  • ****
  • Posts: 303
Re: Reference counting plz?
« Reply #88 on: September 08, 2014, 01:38:42 pm »
I don't see how is it not possible; but whatever, I think I will take your word for it because I definitely don't feel like studying FPC compiler source myself
Too late to escape fate

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Reference counting plz?
« Reply #89 on: September 09, 2014, 10:56:36 am »
Unfortunately I don't have money for Oxygene
You can take a look at FPC JVM:
http://wiki.freepascal.org/FPC_JVM
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

 

TinyPortal © 2005-2018