Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-04

FPImage and GetDataLineStart

63 messages · 13 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sven Barth
to Leonardo M. Ramé
Leonardo M. Ramé wrote
Hi, I need to write a function that replaces TLazIntfImage by using fpImage, and I can't find an alternative to GetDataLineStart. How can I replace it?.

Maybe I get your intention wrong, but TLazIntfImage is already using fpImage and it derives from a TFPCustomImage itself.

Regards,
Sven

Reply by email

Marco van de Voort
to Sven Barth

In our previous episode, Sven Barth said:

Show quoted text 5 lines
Am 20.04.2011 22:20, schrieb Leonardo M. Ram?: > Hi, I need to write a function that replaces TLazIntfImage by using fpImage, and I can't find an alternative to GetDataLineStart. How can I replace it?. Maybe I get your intention wrong, but TLazIntfImage is already using fpImage and it derives from a TFPCustomImage itself.

True, but TFPCustomImage is abstact wrt memory layout and doens't provide row level access, only pixel level access.

Only TFPMemoryImage adds the memory access, but IIRC only 64-bit pixels. (16-bit RGBA)

While these abstractions make it easy to make fp/fcl-image somewhat complete, they are also very memory hungry and slow.

IIRC I accelerated loading/saving simple 8-bit BMP images 20 to 50 times in my work code.

Reply by email

Luiz Americo Pereira Camara
to Marco van de Voort
Marco van de Voort wrote 13 lines
In our previous episode, Sven Barth said: > Am 20.04.2011 22:20, schrieb Leonardo M. Ram?: >> Hi, I need to write a function that replaces TLazIntfImage by using fpImage, and I can't find an alternative to GetDataLineStart. How can I replace it?. > Maybe I get your intention wrong, but TLazIntfImage is already using > fpImage and it derives from a TFPCustomImage itself. True, but TFPCustomImage is abstact wrt memory layout and doens't provide row level access, only pixel level access. Only TFPMemoryImage adds the memory access, but IIRC only 64-bit pixels. (16-bit RGBA) While these abstractions make it easy to make fp/fcl-image somewhat complete, they are also very memory hungry and slow.

Besides that there's not a uniform correlation between 16bit and 8bit. See thread

the Lazarus implementation does the following to convert TColor (each color channel with 8bit) to TFPColor (16bit channels):

8bit to 16bit : set low and high memory of each 16bit channel to the 8bit counterpart
if 8bit Red channel is $0F the 16bit Red will be $0F0F

16bit to 8bit: get the high memory of each 16bit channel 16 16bit Red is $001F the 8bit red will be $00

IMO is just wasting memory at least in the current implementation that takes no advantage of the wider color range.

Luiz

Show quoted text 8 lines
IIRC I accelerated loading/saving simple 8-bit BMP images 20 to 50 times in my work code. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Leonardo M. Ramé
to Marco van de Voort: In our previous episode, Sven Barth said: True, but TFPCustomImage is abstact wrt memory…
Marco van de Voort wrote 31 lines
From: Marco van de Voort Subject: Re: [fpc-pascal] FPImage and GetDataLineStart To: "FPC-Pascal users discussions" Date: Thursday, April 21, 2011, 6:41 AM In our previous episode, Sven Barth said: > Am 20.04.2011 22:20, schrieb Leonardo M. Ram?: > > Hi, I need to write a function that replaces TLazIntfImage by using fpImage, and I can't find an alternative to GetDataLineStart. How can I replace it?. > > Maybe I get your intention wrong, but TLazIntfImage is already using > fpImage and it derives from a TFPCustomImage itself. True, but TFPCustomImage is abstact wrt memory layout and doens't provide row level access, only pixel level access. Only TFPMemoryImage adds the memory access, but IIRC only 64-bit pixels. (16-bit RGBA) While these abstractions make it easy to make fp/fcl-image somewhat complete, they are also very memory hungry and slow. IIRC I accelerated loading/saving simple 8-bit BMP images 20 to 50 times in my work code.

Do you care to share some insights about what you did to accelerate it?

Leonardo M. Ramé
http://leonardorame.blogspot.com

Reply by email

Marco van de Voort
to Leonardo M. Ramé

In our previous episode, Leonardo M. Ram? said:

Show quoted text 6 lines
> IIRC I accelerated loading/saving simple 8-bit BMP images > 20 to 50 times in > my work code. > Do you care to share some insights about what you did to accelerate it?

- Made it 8bpp only
- introduced linebased writing.
- since my images are only 32-bit aligned, just blockwrite their pixeldata in one run.
- I've no backwards compatibility limitations. IOW the images are not GDI compatible, since drawing goes via opengl.

For me this was all important, since writing bmps was the only non zero copy part in my image processing trajectory.

I've a newer set up based on generics that uses one template for 8,16,32 bits images. It is not finished though, and uses Delphi style generics.

The code is written for Delphi, but when I need it I port it to FPC too. The generic one hasn't been ported to FPC.

Since all these are based on fcl-image code, they are opensourcable, but they need to be extracted and cleaned up. But I put a snapshot here:

http://www.stack.nl/~marcov/bimagerelease.zip

Notes:
- baseimage is the 8bpp class that is in production. Bmp writing is integrated. pnghandler is a simple base class to read/write pngs.
- baseimagegen is the same, but redone generic. I use it mostly for experiments, and it is NOT production use, and in Delphi generics dialect. (which FPC doesn't support yet)
- pbbyte is a pointer to a one byte value that can be overindexed ( like x[2]). pbyte on Delphi 2009+ and FPC, and pchar on older Delphi's

The baseimagegen was mostly proof of concept. It derives a generic class from a non generic baseclass. This allows to use the generic derived classes in performance specific code, and the general base class for cases where it matter less.

The generic code has some nested types to allow processing code somewhat independant of pixel size in a way that it is still optimal.

Typical code would look like this:

procedure something (img :TBW8Image);  // 8 bit grayscale
var ppixel,ppixelend : img.reft; // pointer type always the same as the parameter expects
    x, y : integer;
    pixvalue : img.baseunit;  // whatever our pixel type is.
begin
  for y:=0 to img.imageheight-1 do
   begin
     ppixel:=img.getimagepointer(0,y);   // inlinable in theory, 4-6 instructions
     ppixelend:=ppixel[img.imagewidth];
     while (ppixel<ppixelend) do  // 1 moving var in this loop.
       begin
         pixvalue:=ppixel^;
         // operate on pixvalue or use ppixel^ directly.
         inc(ppixel);
       end;
   end;

Note that this walking of the image is independant if the image is stored topdown or not. And the general skeleton of the code (should) remain(s) working if I change the parameter from 8-bit to 16-bit.

In reality, the Delphi optimizer doesn't do a absolutely great job when inlining such generalized inline methods. But even halfway is already quite optimal.

Reply by email

Unknown author
to Leonardo M. Ramé: Do you care to share some insights about what you did to accelerate it? Leonardo M. Ramé…
Leonardo M. Ramé wrote 35 lines
--- On Thu, 4/21/11, Marco van de Voort wrote: > From: Marco van de Voort > Subject: Re: [fpc-pascal] FPImage and GetDataLineStart > To: "FPC-Pascal users discussions" > Date: Thursday, April 21, 2011, 6:41 AM > In our previous episode, Sven Barth > said: > > Am 20.04.2011 22:20, schrieb Leonardo M. Ram?: > > > Hi, I need to write a function that replaces > TLazIntfImage by using fpImage, and I can't find an > alternative to GetDataLineStart. How can I replace it?. > > > > Maybe I get your intention wrong, but TLazIntfImage is > already using > > fpImage and it derives from a TFPCustomImage itself. > > True, but TFPCustomImage is abstact wrt memory layout and > doens't provide > row level access, only pixel level access. > > Only TFPMemoryImage adds the memory access, but IIRC only > 64-bit pixels. > (16-bit RGBA) > > While these abstractions make it easy to make fp/fcl-image > somewhat > complete, they are also very memory hungry and slow. > > IIRC I accelerated loading/saving simple 8-bit BMP images > 20 to 50 times in > my work code. > Do you care to share some insights about what you did to accelerate it?

It is really very easy to accelerate it:

* Create a TFPCustomImage descendant that is limited to the bit depth you need.
* Do not use palette.
* Implement GetPixel and SetPixel so they convert from 64-bit from/to the depth you used
* Implement a GetScanLine/SetScanLine specific to your bit depth.

You can now load/save the image very fast using the GetScanLine/SetScanLine, and all other FPIMage operations will work equally well.

Following prior discussions on the list, I have a sample implementation ready (simple RGB, no alpha), but it is not yet committed. It's maybe 20 lines of code.

I'll try and commit it tonight.

Michael.

Reply by email

Leonardo M. Ramé
to Unknown author
Show quoted text 79 lines
From: Subject: Re: [fpc-pascal] FPImage and GetDataLineStart To: "FPC-Pascal users discussions" Date: Thursday, April 21, 2011, 11:09 AM On Thu, 21 Apr 2011, Leonardo M. Ramé wrote: > --- On Thu, 4/21/11, Marco van de Voort wrote: > >> From: Marco van de Voort >> Subject: Re: [fpc-pascal] FPImage and GetDataLineStart >> To: "FPC-Pascal users discussions" >> Date: Thursday, April 21, 2011, 6:41 AM >> In our previous episode, Sven Barth >> said: >> > Am 20.04.2011 22:20, schrieb Leonardo M. Ram?: >> > > Hi, I need to write a function that replaces >> TLazIntfImage by using fpImage, and I can't find an >> alternative to GetDataLineStart. How can I replace it?. >> > > Maybe I get your intention wrong, but TLazIntfImage is >> already using > fpImage and it derives from a TFPCustomImage itself. >> >> True, but TFPCustomImage is abstact wrt memory layout and >> doens't provide >> row level access, only pixel level access. >> >> Only TFPMemoryImage adds the memory access, but IIRC only >> 64-bit pixels. >> (16-bit RGBA) >> >> While these abstractions make it easy to make fp/fcl-image >> somewhat >> complete, they are also very memory hungry and slow. >> >> IIRC I accelerated loading/saving simple 8-bit BMP images >> 20 to 50 times in >> my work code. >> > > Do you care to share some insights about what you did to accelerate it? It is really very easy to accelerate it: * Create a TFPCustomImage descendant that is limited to the bit depth you need. * Do not use palette. * Implement GetPixel and SetPixel so they convert from 64-bit from/to the depth you used * Implement a GetScanLine/SetScanLine specific to your bit depth. You can now load/save the image very fast using the GetScanLine/SetScanLine, and all other FPIMage operations will work equally well. Following prior discussions on the list, I have a sample implementation ready (simple RGB, no alpha), but it is not yet committed. It's maybe 20 lines of code. I'll try and commit it tonight. Michael. -----Inline Attachment Follows-----

Thanks Michael and Marco, now I have a *more* clever idea of how to do it.

Leonardo M. Ramé
http://leonardorame.blogspot.com

Reply by email

Marco van de Voort
to Unknown author: It is really very easy to accelerate it: * Create a TFPCustomImage descendant that is…

In our previous episode, said:

Show quoted text 7 lines
* Create a TFPCustomImage descendant that is limited to the bit depth you need. * Do not use palette. * Implement GetPixel and SetPixel so they convert from 64-bit from/to the depth you used * Implement a GetScanLine/SetScanLine specific to your bit depth. You can now load/save the image very fast using the GetScanLine/SetScanLine, and all other FPIMage operations will work equally well.

This will not accelerate writing (or any other
form of streaming), there will still be a procedure call per pixel and conversion to/from 64-bit.

However I've done some attempts and research to see what it would take to fix this, and within the fcl-image I've found no solution without invalidating the concept.

The only sane solution (long term) is to convert fcl-image to a generic class, and make some of the aspects generic. (e.g. for a yuv422 image you need to define a record with several inline static methods and then parameterize some generic yuv class that is a descendant of a generic 8-bit storage class etc) with that record. (the generic yuv class then knows what methods to call, and are somewhat efficient due to the inlining)

The fun part is that you can still implement the current way as baseline this way, and then progressively implement quicker variants.

Reply by email

Mattias Gaertner
to Marco van de Voort

 
 

Marco van de Voort hat am 21. April 2011 um 18:50 geschrieben:

Show quoted text 15 lines
In our previous episode, said: > * Create a TFPCustomImage descendant that is limited to the bit depth you > need. > * Do not use palette. > * Implement GetPixel and SetPixel so they convert from 64-bit from/to the > depth you used > * Implement a GetScanLine/SetScanLine specific to your bit depth. > > You can now load/save the image very fast using the > GetScanLine/SetScanLine, > and all other FPIMage operations will work equally well. This will not accelerate writing (or any other form of streaming), there will still be a procedure call per pixel and conversion to/from 64-bit. 

Yes, it does, because of cache effects.
I use it my programs and a 32bit per pixel fpmemoryimage is about twice as fast as a 64bit per pixel. 
And 24bit RGB or 8bit grayscale is even faster.
 

 

Show quoted text 12 lines
However I've done some attempts and research to see what it would take to fix this, and within the fcl-image I've found no solution without invalidating the concept. The only sane solution (long term) is to convert fcl-image to a generic class, and make some of the aspects generic.  (e.g.  for a yuv422 image you need to define a record with several inline static methods and then parameterize some generic yuv class that is a descendant of a generic 8-bit storage class etc) with that record. (the generic yuv class then knows what methods to call, and are somewhat efficient due to the inlining) 

Can you give an example, how this should work?
For example, how would you alter the following routine:  
procedure PaintSomething(img: TFPCustomImage);
var x,y: integer; 
begin
  for y:=10 to img.Height-10 do  
    for x:=10 to img.Width-10 do  
      img.Colors[x,y]:=colRed; 
end;  
 

The fun part is that you can still implement the current way as baseline this way, and then progressively implement quicker variants.

Note: TLazIntfImage already contains a lot of access functions for many common memory formats.

Mattias

Reply by email

Marco van de Voort
to Mattias Gaertner

In our previous episode, Mattias Gaertner said:

Show quoted text 7 lines
> > GetScanLine/SetScanLine, > > and all other FPIMage operations will work equally well. > > This will not accelerate writing (or any other > form of streaming), there will still be a procedure call per pixel and > conversion to/from 64-bit.? Yes, it does, because of cache effects.

Throw away an euro, gain 2 cents.

Show quoted text 16 lines
> class, and make some of the aspects generic.? (e.g.? for a yuv422 image you > need to define a record with several inline static methods and then > parameterize > some generic yuv class that is a descendant of a generic 8-bit storage > class etc) with that record. (the generic yuv class then knows what methods > to call, and are somewhat efficient due to the inlining)? Can you give an example, how this should work? For example, how would you alter the following routine: ? procedure PaintSomething(img: TFPCustomImage); var x,y: integer;? begin ? for y:=10 to img.Height-10 do ? ??? for x:=10 to img.Width-10 do ? ????? img.Colors[x,y]:=colRed;? end; ?

It is pixel level access, so it won't be optimized. Which is exactly the problem, since currently fcl-image doesn't provide anything but pixel level access.

If I went theoretical, the only advantage is that img could be a generic derivate that implements the exact yuv422 storage class which would have the rgb to yuv conversion inlined for the exact yuv and rgb types. So you would keep the virtual call, but the code in it would be generated for the specific tcolor32 (Tcolor64?) to yuv422 conversion.

HOWEVER, if your procedure actually named the specific type, it would be a lot faster. So if you only generate say RGBA 32-bit images, the above code would _NOT_ call any procedure, since the whole shebang would be inlinable, and in ideal cases could get pretty close to ideal due to cse or hoisting of invariants.

STILL that is not the objective. The main objective is to allow fast line based access using the native types for the "easy" types.

1) providing several speedy base storage sizes (8,16,32,64 bit maybe 24 too) without duplicating code.

2) provide row access for these basic types. Yes, I know. It doesn't exactly provide for 12-bit packed access, which means such types would still follow the slow "generic" way by mapping those to 64bpp.

> The fun part is that you can still implement the current way as baseline > this way, and then progressively implement quicker variants. Note: TLazIntfImage already contains a lot of access functions for many common memory formats.

I know. But see above generics class. It is 500 lines, and provides the pretty much same without case statements, virtual procedures, nothing.

If you declare your class as e.g. TBW32image (RGBA), a pixel assignment is an inline handful of instructions.

I think fcl-image with its no-compromise format support was great initial effort. But it is time to at least allow some internal shortcuts for performance's sake. And generics allow a way to put this into a class hierarchy without too much code duplication.

Reply by email

Michael Van Canneyt
to Marco van de Voort
Marco van de Voort wrote 17 lines
In our previous episode, Mattias Gaertner said: > >> GetScanLine/SetScanLine, > >> and all other FPIMage operations will work equally well. > > > > This will not accelerate writing (or any other > > form of streaming), there will still be a procedure call per pixel and > > conversion to/from 64-bit.? > Yes, it does, because of cache effects. If you declare your class as e.g. TBW32image (RGBA), a pixel assignment is an inline handful of instructions. I think fcl-image with its no-compromise format support was great initial effort. But it is time to at least allow some internal shortcuts for performance's sake. And generics allow a way to put this into a class hierarchy without too much code duplication.

You can propose whatever you want _but_ generics.

Michael.

Reply by email

Michael Van Canneyt
to Marco van de Voort: In our previous episode, said: This will not accelerate writing (or any other form of…
Marco van de Voort wrote 12 lines
In our previous episode, said: > * Create a TFPCustomImage descendant that is limited to the bit depth you need. > * Do not use palette. > * Implement GetPixel and SetPixel so they convert from 64-bit from/to the depth you used > * Implement a GetScanLine/SetScanLine specific to your bit depth. > > You can now load/save the image very fast using the GetScanLine/SetScanLine, > and all other FPIMage operations will work equally well. This will not accelerate writing (or any other form of streaming), there will still be a procedure call per pixel and conversion to/from 64-bit.

Obviously not if you use the standard reader classes.

But if the data is available as scanlines: definitely. That was the implicit assumption.

There is no generic way to solve this problem, because you'd need a matrix covering all possible storage memory formats and all possible disk storage formats.

The best we can do is create a memory class with some pre-defined memory storages, with appropriate getscanline/setscanline routines and make sure the reader classes can
a) detect them
b) make use of them if they find one matching the file storage format. c) fall back on the current mechanism if no fitting format is found. If well-chosen, this approach should cover most cases.

Michael.

Reply by email

Marco van de Voort
to Michael Van Canneyt

In our previous episode, Michael Van Canneyt said:

There is no generic way to solve this problem, because you'd need a matrix covering all possible storage memory formats and all possible disk storage formats.

Probably. The point is more that mostly only the diagonal of that matrix (dumping the existing memory format to disk) is worth accelerating.

IOW the whole point is to make exceptions for a few often used cases.

Show quoted text 7 lines
The best we can do is create a memory class with some pre-defined memory storages, with appropriate getscanline/setscanline routines and make sure the reader classes can a) detect them b) make use of them if they find one matching the file storage format. c) fall back on the current mechanism if no fitting format is found. If well-chosen, this approach should cover most cases.

Something like that yes. Still duplication for the various formats though.

Reply by email

Marco van de Voort
to Michael Van Canneyt: You can propose whatever you want _but_ generics. Michael.

In our previous episode, Michael Van Canneyt said:

Show quoted text 9 lines
> If you declare your class as e.g. TBW32image (RGBA), a pixel assignment is > an inline handful of instructions. > > I think fcl-image with its no-compromise format support was great initial > effort. But it is time to at least allow some internal shortcuts for > performance's sake. And generics allow a way to put this into a class > hierarchy without too much code duplication. You can propose whatever you want _but_ generics.

Motivation?

Reply by email

Michael Van Canneyt
to Marco van de Voort
Marco van de Voort wrote 12 lines
In our previous episode, Michael Van Canneyt said: >> If you declare your class as e.g. TBW32image (RGBA), a pixel assignment is >> an inline handful of instructions. >> >> I think fcl-image with its no-compromise format support was great initial >> effort. But it is time to at least allow some internal shortcuts for >> performance's sake. And generics allow a way to put this into a class >> hierarchy without too much code duplication. > > You can propose whatever you want _but_ generics. Motivation?

Threefold:
a) The compiler's handling of generics is still beta code in my opinion. As far as I know, the original problem I reported when writing the docs for them is still not solved.

b) It's demonstratibly slower than optimized classes. (see the whole debate on core when it was started. The problem is not an optimizer one, but the need to revert to slower but more general programming techniques when using generics) Since the idea is to make things faster, generics are a poor choice.

c) I want my own code to be 100% generics-free, and I happen to use fp-image a lot.

But if you want to write generics-based image handling classes, feel free to put them in fcl-stl, just not in fp-image. I'll be glad to make some reasonable changes to the base classes to make this possible.

Michael.

Reply by email

Michael Van Canneyt
to Marco van de Voort: In our previous episode, Michael Van Canneyt said: Probably. The point is more that…
Marco van de Voort wrote 8 lines
In our previous episode, Michael Van Canneyt said: > > There is no generic way to solve this problem, because you'd need a matrix > covering all possible storage memory formats and all possible disk storage > formats. Probably. The point is more that mostly only the diagonal of that matrix (dumping the existing memory format to disk) is worth accelerating.

I don't understand, that precludes any line-based storage format like BMP, XPM ?

IOW the whole point is to make exceptions for a few often used cases.

Yes.
I suspect the lazarus people would be very happy to have TColor support included... (well, I hope they will be ;) )

Show quoted text 10 lines
> The best we can do is create a memory class with some pre-defined memory storages, > with appropriate getscanline/setscanline routines and make sure the reader classes > can > a) detect them > b) make use of them if they find one matching the file storage format. > c) fall back on the current mechanism if no fitting format is found. > If well-chosen, this approach should cover most cases. Something like that yes. Still duplication for the various formats though.

I don't see where the duplication comes in.
There may be duplication in your classes (I don't know, but I suspect it is the reason you switched to generics, to save typing), but with the right delegation classes I think there is no need for duplication...

The thing will be to parametrize the needed storage formats, and then implement the reader support for them.

Michael.

Reply by email

Marco van de Voort
to Michael Van Canneyt: Threefold: a) The compiler's handling of generics is still beta code in my opinion. As…

In our previous episode, Michael Van Canneyt said:

Show quoted text 20 lines
>> You can propose whatever you want _but_ generics. > > Motivation? Threefold: a) The compiler's handling of generics is still beta code in my opinion. As far as I know, the original problem I reported when writing the docs for them is still not solved. b) It's demonstratibly slower than optimized classes. (see the whole debate on core when it was started. The problem is not an optimizer one, but the need to revert to slower but more general programming techniques when using generics) Since the idea is to make things faster, generics are a poor choice. c) I want my own code to be 100% generics-free, and I happen to use fp-image a lot. But if you want to write generics-based image handling classes, feel free to put them in fcl-stl, just not in fp-image. I'll be glad to make some reasonable changes to the base classes to make this possible.

I give you a. To be honest it is still a bit too early for Delphi even. But I don't assume a fully optimized FCL-image is something short term anyway.

I don't understand what you mean with generics is a typed system, and if you focus on the birds-eye of view it is all as fast. (*)

The remark about stuffing generics in STL is something that doesn't make sense. Generics are useless when not used.

As for c, for me it is totally the opposite. Without some thorough speedup, fcl-image is totally unusuable for my purposes, even on the fringes. So for me such things are totally ununderstandable. If you depend on this so much, and with fcl-image having be pretty much static for the last decade, you simply take a copy for own use ?

(*) imgconv takes _seconds_ to do some conversions that coded out in even straight forward pascal take several can understand some generalising making stuff a bit slower, but a factor 1000 is limiting for a lot of uses, and unnecessary stressing the system for the rest. I hope it is clear I'm not talking about one or two instructions in a loop somewhere here, but magnitudes, magnitudes more.

Reply by email

Marco van de Voort
to Michael Van Canneyt: I don't understand, that precludes any line-based storage format like BMP, XPM ? Yes. I…

In our previous episode, Michael Van Canneyt said:

Show quoted text 11 lines
>> The best we can do is create a memory class with some pre-defined memory storages, >> with appropriate getscanline/setscanline routines and make sure the reader classes >> can >> a) detect them >> b) make use of them if they find one matching the file storage format. >> c) fall back on the current mechanism if no fitting format is found. >> If well-chosen, this approach should cover most cases. > > Something like that yes. Still duplication for the various formats though. I don't see where the duplication comes in.

It allows to address multiple points in the imagesize vs reader/writer class matrix (that you described) in one source.

There may be duplication in your classes (I don't know, but I suspect it is delegation classes I think there is no need for duplication...

Basically I use delegation for the slow case, where you operate on the base type.

However when implemented using generics you can also directly use the specialized type, and have fairly quick direct access.

The thing will be to parametrize the needed storage formats, and then implement the reader support for them.

How will you implement reader support for many memory layouts?

Reply by email

Sven Barth
to Michael Van Canneyt: Threefold: a) The compiler's handling of generics is still beta code in my opinion. As…
Michael Van Canneyt wrote 15 lines
On Thu, 21 Apr 2011, Marco van de Voort wrote: > In our previous episode, Michael Van Canneyt said: >> >> You can propose whatever you want _but_ generics. > > Motivation? Threefold: a) The compiler's handling of generics is still beta code in my opinion. As far as I know, the original problem I reported when writing the docs for them is still not solved.

May I ask out of curiosity which problem you mean?

Regards,
Sven

Reply by email

Michael Van Canneyt
to Marco van de Voort: In our previous episode, Michael Van Canneyt said: It allows to address multiple points…
Marco van de Voort wrote 25 lines
In our previous episode, Michael Van Canneyt said: >>> The best we can do is create a memory class with some pre-defined memory storages, >>> with appropriate getscanline/setscanline routines and make sure the reader classes >>> can >>> a) detect them >>> b) make use of them if they find one matching the file storage format. >>> c) fall back on the current mechanism if no fitting format is found. >>> If well-chosen, this approach should cover most cases. >> >> Something like that yes. Still duplication for the various formats though. > > I don't see where the duplication comes in. It allows to address multiple points in the imagesize vs reader/writer class matrix (that you described) in one source. > There may be duplication in your classes (I don't know, but I suspect it is > delegation classes I think there is no need for duplication... Basically I use delegation for the slow case, where you operate on the base type. However when implemented using generics you can also directly use the specialized type, and have fairly quick direct access.

You don't need generics for that. Any form of an array of bytes will do, since that's what it amounts to in the end anyway.

> The thing will be to parametrize the needed storage formats, and then implement > the reader support for them. How will you implement reader support for many memory layouts?

I am not that definite in my design. But I'm willing to listen to ideas. (barring the ones relying on the use of generics)

Michael.

Reply by email

Jonas Maebe
to Sven Barth: May I ask out of curiosity which problem you mean? Sven
Sven Barth wrote 7 lines
On 21.04.2011 21:45, Michael Van Canneyt wrote: > Threefold: > a) The compiler's handling of generics is still beta code in my opinion. > As far as I know, the original problem I reported when writing the docs > for them is still not solved. May I ask out of curiosity which problem you mean?

The main problem with generics as they are implemented in FPC, is that they are basically macros. That means if you use a type "tsomerecord" in a generic implementation, and in a unit in which the generic is specialised another type with that name is visible, this other type will suddenly be used. The same goes for functions and every other identifier, because it's a token record/replay mechanism.

Jonas

Reply by email

Michael Van Canneyt
to Sven Barth: May I ask out of curiosity which problem you mean? Sven
Sven Barth wrote 18 lines
On 21.04.2011 21:45, Michael Van Canneyt wrote: > > > On Thu, 21 Apr 2011, Marco van de Voort wrote: > >> In our previous episode, Michael Van Canneyt said: >>> >>> You can propose whatever you want _but_ generics. >> >> Motivation? > > Threefold: > a) The compiler's handling of generics is still beta code in my opinion. > As far as I know, the original problem I reported when writing the docs > for them is still not solved. > May I ask out of curiosity which problem you mean?

There were several.

The first one seems solved (see docs, section on 'A word on scope', the local thing), compiler now gives an error (a debatable solution IMHO, but better than the crash at the time.).

Second problem:

The following compiles:

uses ucomplex;
type
   Generic TMyClass<T> = Class(TObject)
     Function Add(A,B : T) : T;
   end;
Function TMyClass.Add(A,B : T) : T;
begin
   Result:=A+B;
end;
Type
   TMyIntegerClass = specialize TMyClass<Integer>;
   TMyComplexClass = specialize TMyClass<Complex>;
end.

but the following does not:

---------------------------------------------------------
unit mya;
interface
type
   Generic TMyClass<T> = Class(TObject)
     Function Add(A,B : T) : T;
   end;
Implementation
Function TMyClass.Add(A,B : T) : T;
begin
   Result:=A+B;
end;
end.
---------------------------------------------------------

and program :

---------------------------------------------------------
program myb;
uses mya, ucomplex;
Type
   TMyIntegerClass = specialize TMyClass<Integer>;
   TMyComplexClass = specialize TMyClass<Complex>;
end.
---------------------------------------------------------

Results in:

home: >fpc -S2 myb.pp
mya.pp(16,12) Error: Operator is not overloaded: "complex" + "complex"
myb.pp(9,14) Fatal: There were 1 errors compiling module, stopping

Which is strange to say the least, as the per the definition/intent of generics, the code in mya should not know anything about the types that will be used when specializing. (in this case complex).

As per the intent of generics the second program above should compile just as well.

But then different rules will apply for operators and procedure calls:
- procedure calls must be resolvable at define time
- Operators must be resolvable at specialization time. No principal problem (we can define it so), but strange at least.

(BTW. The sources of the docs contain a section about this second problem, but it is commented out in the LaTeX sources)

Michael.

Reply by email

Marco van de Voort
to Michael Van Canneyt: You don't need generics for that. Any form of an array of bytes will do, since that's…

In our previous episode, Michael Van Canneyt said:

Show quoted text 6 lines
> > However when implemented using generics you can also directly use the > specialized type, and have fairly quick direct access. You don't need generics for that. Any form of an array of bytes will do, since that's what it amounts to in the end anyway.

But it has to figure out runtime which to use, or you need to duplicate a class for each storage type and deal with delegation overhead.

I've complete understanding for the fact that generics are too early, but IMHO it is the long term solution. Anything else would be madness, or minor damage control at best.

Show quoted text 7 lines
>> The thing will be to parametrize the needed storage formats, and then implement >> the reader support for them. > > How will you implement reader support for many memory layouts? I am not that definite in my design. But I'm willing to listen to ideas. (barring the ones relying on the use of generics)

Last night, we started a fund raiser on IRC to buy you a more recent Delphi version :_-)

Reply by email

Sven Barth
to Michael Van Canneyt: There were several. The first one seems solved (see docs, section on 'A word on scope',…
Michael Van Canneyt wrote 7 lines
But then different rules will apply for operators and procedure calls: - procedure calls must be resolvable at define time - Operators must be resolvable at specialization time. No principal problem (we can define it so), but strange at least. (BTW. The sources of the docs contain a section about this second problem, but it is commented out in the LaTeX sources)

Thank you Michael (and thank you, too, Jonas) for your explanation.

I'll keep an eye on this problem.

Regards,
Sven

Reply by email

Unknown author
to Marco van de Voort: In our previous episode, Michael Van Canneyt said: But it has to figure out runtime which…
Marco van de Voort wrote 14 lines
In our previous episode, Michael Van Canneyt said: >> >> However when implemented using generics you can also directly use the >> specialized type, and have fairly quick direct access. > > You don't need generics for that. Any form of an array of bytes will do, > since that's what it amounts to in the end anyway. But it has to figure out runtime which to use, or you need to duplicate a class for each storage type and deal with delegation overhead. I've complete understanding for the fact that generics are too early, but IMHO it is the long term solution. Anything else would be madness, or minor damage of the more "recent" or "new" languages I know do not have generics,

which puts a question mark beside the 'long term' and 'madness'. One could argue that generics itself is "damage control", on a language level, for the "old languages" to alleviate the restrictions of strict typing.

Generics in FPC are a typing aid, borrowed from C++, no more, no less. This is an old discussion, which I will not repeat.

So please stop using nice sounding one-liners like 'madness' and "long-term solutions", "damage control". They are highly subjective and therefore of no value, as they only put your beliefs against mine.

Show quoted text 10 lines
>>> The thing will be to parametrize the needed storage formats, and then implement >>> the reader support for them. >> >> How will you implement reader support for many memory layouts? > > I am not that definite in my design. But I'm willing to listen to ideas. > (barring the ones relying on the use of generics) Last night, we started a fund raiser on IRC to buy you a more recent Delphi version :_-)

Please dispense with the dialectic tricks.

fcl-image is meanwhile more long-lived than many other FPC components out there. Yes, it has a speed issue. I am aware of that since a long time and am willing to work on it. I did the bulk of the design and maintenance in the past, I'll handle this as well.

So you can cooperate with me and propose solutions that I'm willing to implement and spend time on, or continue this sterile discussion about something which you know I will not accept anyway.

Michael.

Reply by email

Florian Klämpfl
to Jonas Maebe: The main problem with generics as they are implemented in FPC, is that they are basically…
Jonas Maebe wrote 17 lines
On 21 Apr 2011, at 23:26, Sven Barth wrote: > On 21.04.2011 21:45, Michael Van Canneyt wrote: >> Threefold: a) The compiler's handling of generics is still beta >> code in my opinion. As far as I know, the original problem I >> reported when writing the docs for them is still not solved. > > May I ask out of curiosity which problem you mean? The main problem with generics as they are implemented in FPC, is that they are basically macros. That means if you use a type "tsomerecord" in a generic implementation, and in a unit in which the generic is specialised another type with that name is visible, this other type will suddenly be used. The same goes for functions and every other identifier, because it's a token record/replay mechanism.

No. The symtablestack state is restore. But this leads to other problems like overloaded operators for the current type being ignored.

Reply by email

Florian Klämpfl
to Florian Klämpfl
Florian Klämpfl wrote 21 lines
Am 22.04.2011 00:08, schrieb Jonas Maebe: > > On 21 Apr 2011, at 23:26, Sven Barth wrote: > >> On 21.04.2011 21:45, Michael Van Canneyt wrote: >>> Threefold: a) The compiler's handling of generics is still beta >>> code in my opinion. As far as I know, the original problem I >>> reported when writing the docs for them is still not solved. >> >> May I ask out of curiosity which problem you mean? > > The main problem with generics as they are implemented in FPC, is > that they are basically macros. That means if you use a type > "tsomerecord" in a generic implementation, and in a unit in which the > generic is specialised another type with that name is visible, this > other type will suddenly be used. The same goes for functions and > every other identifier, because it's a token record/replay > mechanism. No. The symtablestack state is restore. But this leads to other problems like overloaded operators for the current type being ignored.

See
http://bugs.freepascal.org/view.php?id=15480

Reply by email

Florian Klämpfl
to Michael Van Canneyt: There were several. The first one seems solved (see docs, section on 'A word on scope',…
Michael Van Canneyt wrote 109 lines
On Thu, 21 Apr 2011, Sven Barth wrote: > On 21.04.2011 21:45, Michael Van Canneyt wrote: >> >> >> On Thu, 21 Apr 2011, Marco van de Voort wrote: >> >>> In our previous episode, Michael Van Canneyt said: >>>> >>>> You can propose whatever you want _but_ generics. >>> >>> Motivation? >> >> Threefold: >> a) The compiler's handling of generics is still beta code in my opinion. >> As far as I know, the original problem I reported when writing the docs >> for them is still not solved. >> > > May I ask out of curiosity which problem you mean? There were several. The first one seems solved (see docs, section on 'A word on scope', the local thing), compiler now gives an error (a debatable solution IMHO, but better than the crash at the time.). Second problem: The following compiles: uses ucomplex; type Generic TMyClass<T> = Class(TObject) Function Add(A,B : T) : T; end; Function TMyClass.Add(A,B : T) : T; begin Result:=A+B; end; Type TMyIntegerClass = specialize TMyClass<Integer>; TMyComplexClass = specialize TMyClass<Complex>; end. but the following does not: --------------------------------------------------------- unit mya; interface type Generic TMyClass<T> = Class(TObject) Function Add(A,B : T) : T; end; Implementation Function TMyClass.Add(A,B : T) : T; begin Result:=A+B; end; end. --------------------------------------------------------- and program : --------------------------------------------------------- program myb; uses mya, ucomplex; Type TMyIntegerClass = specialize TMyClass<Integer>; TMyComplexClass = specialize TMyClass<Complex>; end. --------------------------------------------------------- Results in: home: >fpc -S2 myb.pp mya.pp(16,12) Error: Operator is not overloaded: "complex" + "complex" myb.pp(9,14) Fatal: There were 1 errors compiling module, stopping Which is strange to say the least, as the per the definition/intent of generics, the code in mya should not know anything about the types that will be used when specializing. (in this case complex). As per the intent of generics the second program above should compile just as well. But then different rules will apply for operators and procedure calls: - procedure calls must be resolvable at define time - Operators must be resolvable at specialization time. No principal problem (we can define it so), but strange at least.

It is correct that the second doesn't compile. To make the second compile, the overloaded operators for the complex type must be defined inside complex (which was/is? not possible).

Reply by email

Sven Barth
to Florian Klämpfl: See http://bugs.freepascal.org/view.php?id=15480
Florian Klämpfl wrote 25 lines
Am 22.04.2011 11:18, schrieb Florian Klämpfl: > Am 22.04.2011 00:08, schrieb Jonas Maebe: >> >> On 21 Apr 2011, at 23:26, Sven Barth wrote: >> >>> On 21.04.2011 21:45, Michael Van Canneyt wrote: >>>> Threefold: a) The compiler's handling of generics is still beta >>>> code in my opinion. As far as I know, the original problem I >>>> reported when writing the docs for them is still not solved. >>> >>> May I ask out of curiosity which problem you mean? >> >> The main problem with generics as they are implemented in FPC, is >> that they are basically macros. That means if you use a type >> "tsomerecord" in a generic implementation, and in a unit in which the >> generic is specialised another type with that name is visible, this >> other type will suddenly be used. The same goes for functions and >> every other identifier, because it's a token record/replay >> mechanism. > > No. The symtablestack state is restore. But this leads to other problems > like overloaded operators for the current type being ignored. See http://bugs.freepascal.org/view.php?id=15480

Ok, thanks.

What about the folling idea (this might not sound ideal yet, but it's a first idea - at least for me ^^):
* scan all symtables for operators for the types that are used for specialisation
* add these operators to a temporary symtable
* insert this symtable into the restored stack (currently I don't know the best location to put it in though)
* free the temporary symtable (without freeing the operator symbols of course) when the stack is reset

Regards,
Sven

Reply by email

Sven Barth
to Florian Klämpfl: It is correct that the second doesn't compile. To make the second compile, the overloaded…
Florian Klämpfl wrote 114 lines
Am 22.04.2011 00:31, schrieb Michael Van Canneyt: > > > On Thu, 21 Apr 2011, Sven Barth wrote: > >> On 21.04.2011 21:45, Michael Van Canneyt wrote: >>> >>> >>> On Thu, 21 Apr 2011, Marco van de Voort wrote: >>> >>>> In our previous episode, Michael Van Canneyt said: >>>>> >>>>> You can propose whatever you want _but_ generics. >>>> >>>> Motivation? >>> >>> Threefold: >>> a) The compiler's handling of generics is still beta code in my opinion. >>> As far as I know, the original problem I reported when writing the docs >>> for them is still not solved. >>> >> >> May I ask out of curiosity which problem you mean? > > There were several. > > The first one seems solved (see docs, section on 'A word on scope', the > local thing), compiler now gives an error (a debatable solution IMHO, > but better than the crash at the time.). > > Second problem: > > The following compiles: > > uses ucomplex; > > type > Generic TMyClass<T> = Class(TObject) > Function Add(A,B : T) : T; > end; > > > Function TMyClass.Add(A,B : T) : T; > > begin > Result:=A+B; > end; > > > Type > TMyIntegerClass = specialize TMyClass<Integer>; > TMyComplexClass = specialize TMyClass<Complex>; > > end. > > but the following does not: > > --------------------------------------------------------- > unit mya; > > interface > > type > Generic TMyClass<T> = Class(TObject) > Function Add(A,B : T) : T; > end; > > Implementation > > Function TMyClass.Add(A,B : T) : T; > > begin > Result:=A+B; > end; > > end. > --------------------------------------------------------- > > and program : > > --------------------------------------------------------- > program myb; > > uses mya, ucomplex; > > Type > TMyIntegerClass = specialize TMyClass<Integer>; > TMyComplexClass = specialize TMyClass<Complex>; > > end. > --------------------------------------------------------- > > Results in: > > home:>fpc -S2 myb.pp > mya.pp(16,12) Error: Operator is not overloaded: "complex" + "complex" > myb.pp(9,14) Fatal: There were 1 errors compiling module, stopping > > Which is strange to say the least, as the per the definition/intent of > generics, the code in mya should not know anything about the types that > will be used when specializing. (in this case complex). > > As per the intent of generics the second program above should compile > just as well. > > But then different rules will apply for operators and procedure calls: > - procedure calls must be resolvable at define time > - Operators must be resolvable at specialization time. > No principal problem (we can define it so), but strange at least. > It is correct that the second doesn't compile. To make the second compile, the overloaded operators for the complex type must be defined inside complex (which was/is? not possible).

It should be possible now, I didn't test it though yet.

The question is: should we really restrict the overloads to operators defined inside those structures only? What if the user wants to use a class instead of a record? Or an object? And what if the operators are only defined global like the Variant ones...

Regards,
Sven

Reply by email

Unknown author
to Florian Klämpfl: It is correct that the second doesn't compile. To make the second compile, the overloaded…
Florian Klämpfl wrote 19 lines
> mya.pp(16,12) Error: Operator is not overloaded: "complex" + "complex" > myb.pp(9,14) Fatal: There were 1 errors compiling module, stopping > > Which is strange to say the least, as the per the definition/intent of > generics, the code in mya should not know anything about the types that > will be used when specializing. (in this case complex). > > As per the intent of generics the second program above should compile > just as well. > > But then different rules will apply for operators and procedure calls: > - procedure calls must be resolvable at define time > - Operators must be resolvable at specialization time. > No principal problem (we can define it so), but strange at least. > It is correct that the second doesn't compile. To make the second compile, the overloaded operators for the complex type must be defined inside complex (which was/is? not possible).

1. The + is not defined 'inside' integer either. Why should it be required for a record ? What kind of strange reasoning is that ? Are we going to redesign operators for records ? (I suspect this is why it is possible to add type restrictions in the Delphi/.Net implementations)

2. If I have my own overloaded version of '+' for a record, the above means that it cannot ever be used for generics, while it will be used for all my other code.

Say I define a type, and decide not to put the operators inside the record, for whatever reason. I am happily unaware of generics. Along comes an afficiniado of generics, and wants to use my type in generics, but hits the above problem. He is stuck.

Michael.

Reply by email

Unknown author
to Sven Barth: It should be possible now, I didn't test it though yet. The question is: should we really…
Sven Barth wrote 10 lines
> It is correct that the second doesn't compile. To make the second > compile, the overloaded operators for the complex type must be defined > inside complex (which was/is? not possible). It should be possible now, I didn't test it though yet. The question is: should we really restrict the overloads to operators defined inside those structures only? What if the user wants to use a class instead of a record? Or an object? And what if the operators are only defined global like the Variant ones...

Exactly the point I was trying to make.

Michael.

Reply by email

Florian Klämpfl
to Unknown author: 1. The + is not defined 'inside' integer either. Why should it be required for a record ?…

Am 22.04.2011 12:06, schrieb

Show quoted text 27 lines
On Fri, 22 Apr 2011, Florian Klämpfl wrote: >> mya.pp(16,12) Error: Operator is not overloaded: "complex" + "complex" >> myb.pp(9,14) Fatal: There were 1 errors compiling module, stopping >> >> Which is strange to say the least, as the per the definition/intent of >> generics, the code in mya should not know anything about the types that >> will be used when specializing. (in this case complex). >> >> As per the intent of generics the second program above should compile >> just as well. >> >> But then different rules will apply for operators and procedure calls: >> - procedure calls must be resolvable at define time >> - Operators must be resolvable at specialization time. >> No principal problem (we can define it so), but strange at least. >> > > It is correct that the second doesn't compile. To make the second > compile, the overloaded operators for the complex type must be defined > inside complex (which was/is? not possible). 1. The + is not defined 'inside' integer either. Why should it be required for a record ?

Internal types are special.

What kind of strange reasoning is that ? Are we going to redesign operators for records ?

For pascal like generics it might be necessary to rethink some design considerations, yes.

Show quoted text 12 lines
(I suspect this is why it is possible to add type restrictions in the Delphi/.Net implementations) 2. If I have my own overloaded version of '+' for a record, the above means that it cannot ever be used for generics, while it will be used for all my other code. Say I define a type, and decide not to put the operators inside the record, for whatever reason. I am happily unaware of generics. Along comes an afficiniado of generics, and wants to use my type in generics, but hits the above problem. He is stuck.

No. He can define a record helper operator. The question is simple: do we want generics behave like macros or more like .Net generics. Some hybrid approach is imo wrong.

Reply by email

Florian Klämpfl
to Sven Barth: It should be possible now, I didn't test it though yet. The question is: should we really…
Sven Barth wrote 122 lines
On 22.04.2011 11:23, Florian Klämpfl wrote: > Am 22.04.2011 00:31, schrieb Michael Van Canneyt: >> >> >> On Thu, 21 Apr 2011, Sven Barth wrote: >> >>> On 21.04.2011 21:45, Michael Van Canneyt wrote: >>>> >>>> >>>> On Thu, 21 Apr 2011, Marco van de Voort wrote: >>>> >>>>> In our previous episode, Michael Van Canneyt said: >>>>>> >>>>>> You can propose whatever you want _but_ generics. >>>>> >>>>> Motivation? >>>> >>>> Threefold: >>>> a) The compiler's handling of generics is still beta code in my >>>> opinion. >>>> As far as I know, the original problem I reported when writing the >>>> docs >>>> for them is still not solved. >>>> >>> >>> May I ask out of curiosity which problem you mean? >> >> There were several. >> >> The first one seems solved (see docs, section on 'A word on scope', the >> local thing), compiler now gives an error (a debatable solution IMHO, >> but better than the crash at the time.). >> >> Second problem: >> >> The following compiles: >> >> uses ucomplex; >> >> type >> Generic TMyClass<T> = Class(TObject) >> Function Add(A,B : T) : T; >> end; >> >> >> Function TMyClass.Add(A,B : T) : T; >> >> begin >> Result:=A+B; >> end; >> >> >> Type >> TMyIntegerClass = specialize TMyClass<Integer>; >> TMyComplexClass = specialize TMyClass<Complex>; >> >> end. >> >> but the following does not: >> >> --------------------------------------------------------- >> unit mya; >> >> interface >> >> type >> Generic TMyClass<T> = Class(TObject) >> Function Add(A,B : T) : T; >> end; >> >> Implementation >> >> Function TMyClass.Add(A,B : T) : T; >> >> begin >> Result:=A+B; >> end; >> >> end. >> --------------------------------------------------------- >> >> and program : >> >> --------------------------------------------------------- >> program myb; >> >> uses mya, ucomplex; >> >> Type >> TMyIntegerClass = specialize TMyClass<Integer>; >> TMyComplexClass = specialize TMyClass<Complex>; >> >> end. >> --------------------------------------------------------- >> >> Results in: >> >> home:>fpc -S2 myb.pp >> mya.pp(16,12) Error: Operator is not overloaded: "complex" + "complex" >> myb.pp(9,14) Fatal: There were 1 errors compiling module, stopping >> >> Which is strange to say the least, as the per the definition/intent of >> generics, the code in mya should not know anything about the types that >> will be used when specializing. (in this case complex). >> >> As per the intent of generics the second program above should compile >> just as well. >> >> But then different rules will apply for operators and procedure calls: >> - procedure calls must be resolvable at define time >> - Operators must be resolvable at specialization time. >> No principal problem (we can define it so), but strange at least. >> > > It is correct that the second doesn't compile. To make the second > compile, the overloaded operators for the complex type must be defined > inside complex (which was/is? not possible). It should be possible now, I didn't test it though yet. The question is: should we really restrict the overloads to operators defined inside those structures only?

No. But during spezialication only the symbols are available:
- which were available during definition of the generic
- the symbols of the type parameter arguments

What if the user wants to use a class instead of a record? Or an object?

Those should be allowed to contain operators as well.

And what if the operators are only defined global like the Variant ones...

Variant might be a problem.

Reply by email

Sven Barth
to Florian Klämpfl: It is correct that the second doesn't compile. To make the second compile, the overloaded…
Florian Klämpfl wrote 114 lines
Am 22.04.2011 00:31, schrieb Michael Van Canneyt: > > > On Thu, 21 Apr 2011, Sven Barth wrote: > >> On 21.04.2011 21:45, Michael Van Canneyt wrote: >>> >>> >>> On Thu, 21 Apr 2011, Marco van de Voort wrote: >>> >>>> In our previous episode, Michael Van Canneyt said: >>>>> >>>>> You can propose whatever you want _but_ generics. >>>> >>>> Motivation? >>> >>> Threefold: >>> a) The compiler's handling of generics is still beta code in my opinion. >>> As far as I know, the original problem I reported when writing the docs >>> for them is still not solved. >>> >> >> May I ask out of curiosity which problem you mean? > > There were several. > > The first one seems solved (see docs, section on 'A word on scope', the > local thing), compiler now gives an error (a debatable solution IMHO, > but better than the crash at the time.). > > Second problem: > > The following compiles: > > uses ucomplex; > > type > Generic TMyClass<T> = Class(TObject) > Function Add(A,B : T) : T; > end; > > > Function TMyClass.Add(A,B : T) : T; > > begin > Result:=A+B; > end; > > > Type > TMyIntegerClass = specialize TMyClass<Integer>; > TMyComplexClass = specialize TMyClass<Complex>; > > end. > > but the following does not: > > --------------------------------------------------------- > unit mya; > > interface > > type > Generic TMyClass<T> = Class(TObject) > Function Add(A,B : T) : T; > end; > > Implementation > > Function TMyClass.Add(A,B : T) : T; > > begin > Result:=A+B; > end; > > end. > --------------------------------------------------------- > > and program : > > --------------------------------------------------------- > program myb; > > uses mya, ucomplex; > > Type > TMyIntegerClass = specialize TMyClass<Integer>; > TMyComplexClass = specialize TMyClass<Complex>; > > end. > --------------------------------------------------------- > > Results in: > > home:>fpc -S2 myb.pp > mya.pp(16,12) Error: Operator is not overloaded: "complex" + "complex" > myb.pp(9,14) Fatal: There were 1 errors compiling module, stopping > > Which is strange to say the least, as the per the definition/intent of > generics, the code in mya should not know anything about the types that > will be used when specializing. (in this case complex). > > As per the intent of generics the second program above should compile > just as well. > > But then different rules will apply for operators and procedure calls: > - procedure calls must be resolvable at define time > - Operators must be resolvable at specialization time. > No principal problem (we can define it so), but strange at least. > It is correct that the second doesn't compile. To make the second compile, the overloaded operators for the complex type must be defined inside complex (which was/is? not possible).

I just did a quick test: it works in 2.5.1 when the operators are defined inside the record which is used for specialisation.

Regards,
Sven

Reply by email

Sven Barth
to Florian Klämpfl: Am 22.04.2011 12:06, schrieb Internal types are special. For pascal like generics it…
Florian Klämpfl wrote 53 lines
Am 22.04.2011 12:06, schrieb > > > On Fri, 22 Apr 2011, Florian Klämpfl wrote: > >>> mya.pp(16,12) Error: Operator is not overloaded: "complex" + "complex" >>> myb.pp(9,14) Fatal: There were 1 errors compiling module, stopping >>> >>> Which is strange to say the least, as the per the definition/intent of >>> generics, the code in mya should not know anything about the types that >>> will be used when specializing. (in this case complex). >>> >>> As per the intent of generics the second program above should compile >>> just as well. >>> >>> But then different rules will apply for operators and procedure calls: >>> - procedure calls must be resolvable at define time >>> - Operators must be resolvable at specialization time. >>> No principal problem (we can define it so), but strange at least. >>> >> >> It is correct that the second doesn't compile. To make the second >> compile, the overloaded operators for the complex type must be defined >> inside complex (which was/is? not possible). > > > 1. The + is not defined 'inside' integer either. Why should it be > required for a record ? Internal types are special. > What kind of strange reasoning is that ? Are we going to redesign > operators for records ? For pascal like generics it might be necessary to rethink some design considerations, yes. > (I suspect this is why it is possible to add type restrictions in the > Delphi/.Net implementations) > > 2. If I have my own overloaded version of '+' for a record, the above > means that it > cannot ever be used for generics, while it will be used for all my > other code. > > Say I define a type, and decide not to put the operators inside the record, > for whatever reason. I am happily unaware of generics. Along comes an > afficiniado of generics, and wants to use my type in generics, but hits > the above problem. He is stuck. No. He can define a record helper operator. The question is simple: do we want generics behave like macros or more like .Net generics. Some hybrid approach is imo wrong.

Oh dear... I have completely forgotton about operators in record helpers in my implementation...

Nevertheless I don't think this would help in the current situation. Let's assume he uses a 3rd party record that does not contain operators (only global ones) and he uses a 3rd party generic type. Let's further assume that the user can't or does not want to modify those two types. Then he can't use a record helper during the specialization, because that helper isn't available in that time like the global operators defined along side the record aren't.

I must admit though that I have a really bad feeling about my above assumption when I think about my lookup code... so when I enable operators in record helpers it might even work currently by accident O.o

Regards,
Sven

Reply by email

Sven Barth
to Sven Barth
Sven Barth wrote 71 lines
On 22.04.2011 12:18, Florian Klämpfl wrote: > Am 22.04.2011 12:06, schrieb >> >> >> On Fri, 22 Apr 2011, Florian Klämpfl wrote: >> >>>> mya.pp(16,12) Error: Operator is not overloaded: "complex" + "complex" >>>> myb.pp(9,14) Fatal: There were 1 errors compiling module, stopping >>>> >>>> Which is strange to say the least, as the per the definition/intent of >>>> generics, the code in mya should not know anything about the types >>>> that >>>> will be used when specializing. (in this case complex). >>>> >>>> As per the intent of generics the second program above should compile >>>> just as well. >>>> >>>> But then different rules will apply for operators and procedure calls: >>>> - procedure calls must be resolvable at define time >>>> - Operators must be resolvable at specialization time. >>>> No principal problem (we can define it so), but strange at least. >>>> >>> >>> It is correct that the second doesn't compile. To make the second >>> compile, the overloaded operators for the complex type must be defined >>> inside complex (which was/is? not possible). >> >> >> 1. The + is not defined 'inside' integer either. Why should it be >> required for a record ? > > Internal types are special. > >> What kind of strange reasoning is that ? Are we going to redesign >> operators for records ? > > For pascal like generics it might be necessary to rethink some design > considerations, yes. > >> (I suspect this is why it is possible to add type restrictions in the >> Delphi/.Net implementations) >> >> 2. If I have my own overloaded version of '+' for a record, the above >> means that it >> cannot ever be used for generics, while it will be used for all my >> other code. >> >> Say I define a type, and decide not to put the operators inside the >> record, >> for whatever reason. I am happily unaware of generics. Along comes an >> afficiniado of generics, and wants to use my type in generics, but hits >> the above problem. He is stuck. > > No. He can define a record helper operator. The question is simple: do > we want generics behave like macros or more like .Net generics. Some > hybrid approach is imo wrong. Oh dear... I have completely forgotton about operators in record helpers in my implementation... Nevertheless I don't think this would help in the current situation. Let's assume he uses a 3rd party record that does not contain operators (only global ones) and he uses a 3rd party generic type. Let's further assume that the user can't or does not want to modify those two types. Then he can't use a record helper during the specialization, because that helper isn't available in that time like the global operators defined along side the record aren't. I must admit though that I have a really bad feeling about my above assumption when I think about my lookup code... so when I enable operators in record helpers it might even work currently by accident O.o

Ok... it does not work that way currently... (puh) [I tested using a normal function instead of an operator]

Regards,
Sven

Reply by email

Sven Barth
to Florian Klämpfl: Am 22.04.2011 12:06, schrieb Internal types are special. For pascal like generics it…
Florian Klämpfl wrote 53 lines
Am 22.04.2011 12:06, schrieb > > > On Fri, 22 Apr 2011, Florian Klämpfl wrote: > >>> mya.pp(16,12) Error: Operator is not overloaded: "complex" + "complex" >>> myb.pp(9,14) Fatal: There were 1 errors compiling module, stopping >>> >>> Which is strange to say the least, as the per the definition/intent of >>> generics, the code in mya should not know anything about the types that >>> will be used when specializing. (in this case complex). >>> >>> As per the intent of generics the second program above should compile >>> just as well. >>> >>> But then different rules will apply for operators and procedure calls: >>> - procedure calls must be resolvable at define time >>> - Operators must be resolvable at specialization time. >>> No principal problem (we can define it so), but strange at least. >>> >> >> It is correct that the second doesn't compile. To make the second >> compile, the overloaded operators for the complex type must be defined >> inside complex (which was/is? not possible). > > > 1. The + is not defined 'inside' integer either. Why should it be > required for a record ? Internal types are special. > What kind of strange reasoning is that ? Are we going to redesign > operators for records ? For pascal like generics it might be necessary to rethink some design considerations, yes. > (I suspect this is why it is possible to add type restrictions in the > Delphi/.Net implementations) > > 2. If I have my own overloaded version of '+' for a record, the above > means that it > cannot ever be used for generics, while it will be used for all my > other code. > > Say I define a type, and decide not to put the operators inside the record, > for whatever reason. I am happily unaware of generics. Along comes an > afficiniado of generics, and wants to use my type in generics, but hits > the above problem. He is stuck. No. He can define a record helper operator. The question is simple: do we want generics behave like macros or more like .Net generics. Some hybrid approach is imo wrong.

Before I forget it: Why do you think that a hybrid approach is wrong?

Regards,
Sven

Reply by email

Marco van de Voort
to Unknown author: which puts a question mark beside the 'long term' and 'madness'. One could argue that…

In our previous episode, said:

Show quoted text 7 lines
> class for each storage type and deal with delegation overhead. > > I've complete understanding for the fact that generics are too early, but > IMHO it is the long term solution. Anything else would be madness, or minor > damage control at best. Most of the more "recent" or "new" languages I know do not have generics,

What do you mean, C++,C#, Java ?

which puts a question mark beside the 'long term' and 'madness'. One could argue that generics itself is "damage control", on a language level, for the "old languages" to alleviate the restrictions of strict typing.

It eases some cases where that strictness hurts. There are multiple solutions for such cases, e.g. in the database world, people went for variants. Generics are typically for cases where the types are parameterizable.

Show quoted text 6 lines
Generics in FPC are a typing aid, borrowed from C++, no more, no less. This is an old discussion, which I will not repeat. So please stop using nice sounding one-liners like 'madness' and "long-term solutions", "damage control". They are highly subjective and therefore of no value, as they only put your beliefs against mine.

They are as subjective as a one person mandated ban on generics. Even long term.

willing to work on it. I did the bulk of the design and maintenance in the past, I'll handle this as well. So you can cooperate with me and propose solutions that I'm willing to implement and spend time on,

I see no workable solution at this moment. So I'll wait what you have to offer, and see if it matches my own. Otherwise I'll see if I can create some parallel bae library, but that has to wait till generics on FPC are more mature.

Reply by email

Florian Klämpfl
to Sven Barth: Before I forget it: Why do you think that a hybrid approach is wrong? Sven
Sven Barth wrote 5 lines
> No. He can define a record helper operator. The question is simple: do > we want generics behave like macros or more like .Net generics. Some > hybrid approach is imo wrong. Before I forget it: Why do you think that a hybrid approach is wrong?

I meant a semantical hybrid approach, not technical because Users want simply rules how things work. So the rule: "only symbols available during generic definition time are available during specialization" is a simple rule. Every exception like: but operators are available as well are hard to understand for a user.

Reply by email

Florian Klämpfl
to Sven Barth: Oh dear... I have completely forgotton about operators in record helpers in my…
Sven Barth wrote
Oh dear... I have completely forgotton about operators in record helpers in my implementation...

That's the problem with every new language feature: the complexity of the compiler probably increases not with O(n) but something between O(n) and O(n^2).

Show quoted text 9 lines
Nevertheless I don't think this would help in the current situation. Let's assume he uses a 3rd party record that does not contain operators (only global ones) and he uses a 3rd party generic type. Let's further assume that the user can't or does not want to modify those two types. Then he can't use a record helper during the specialization, because that helper isn't available in that time like the global operators defined along side the record aren't.

Well, that's another semantic question: which helpers are available? What's the reason why the helper should not be available. It is part of the type?

Reply by email

Unknown author
to Florian Klämpfl: Am 22.04.2011 12:06, schrieb Internal types are special. For pascal like generics it…
Florian Klämpfl wrote 14 lines
> (I suspect this is why it is possible to add type restrictions in the > Delphi/.Net implementations) > > 2. If I have my own overloaded version of '+' for a record, the above > means that it > cannot ever be used for generics, while it will be used for all my > other code. > > Say I define a type, and decide not to put the operators inside the record, > for whatever reason. I am happily unaware of generics. Along comes an > afficiniado of generics, and wants to use my type in generics, but hits > the above problem. He is stuck. No. He can define a record helper operator.

Which then simply repeats what I already had ?
Very efficient :-)

Michael.

Reply by email

Florian Klämpfl
to Unknown author

Am 22.04.2011 13:32, schrieb

Show quoted text 21 lines
On Fri, 22 Apr 2011, Florian Klämpfl wrote: >> (I suspect this is why it is possible to add type restrictions in the >> Delphi/.Net implementations) >> >> 2. If I have my own overloaded version of '+' for a record, the above >> means that it >> cannot ever be used for generics, while it will be used for all my >> other code. >> >> Say I define a type, and decide not to put the operators inside the >> record, >> for whatever reason. I am happily unaware of generics. Along comes an >> afficiniado of generics, and wants to use my type in generics, but hits >> the above problem. He is stuck. > > No. He can define a record helper operator. Which then simply repeats what I already had ? Very efficient :-)

Speedwise it makes no difference. The difference is to have simple rules which symbols are defined during specialization.

Reply by email

Unknown author
to Marco van de Voort: In our previous episode, said: What do you mean, C++,C#, Java ? It eases some cases…
Marco van de Voort wrote 10 lines
In our previous episode, said: >> class for each storage type and deal with delegation overhead. >> >> I've complete understanding for the fact that generics are too early, but >> IMHO it is the long term solution. Anything else would be madness, or minor >> damage control at best. > > Most of the more "recent" or "new" languages I know do not have generics, What do you mean, C++,C#, Java ?

No, they are "old" languages too. I was more thinking in terms of PHP, Ruby, Python, Javascript (and its variations). I haven't come accross generics for these languages. Yet they are widely adopted.

Show quoted text 8 lines
> which puts a question mark beside the 'long term' and 'madness'. > One could argue that generics itself is "damage control", on a language level, > for the "old languages" to alleviate the restrictions of strict typing. It eases some cases where that strictness hurts. There are multiple solutions for such cases, e.g. in the database world, people went for variants.

I have a database with over 7000 fields, another with 3000, for neither variants are used. Maybe I misunderstand your statement.

Show quoted text 12 lines
Generics are typically for cases where the types are parameterizable. > Generics in FPC are a typing aid, borrowed from C++, no more, no less. > This is an old discussion, which I will not repeat. > So please stop using nice sounding one-liners like 'madness' and "long-term > solutions", "damage control". They are highly subjective and therefore of > no value, as they only put your beliefs against mine. They are as subjective as a one person mandated ban on generics. Even long term.

Exactly, which is why the discussion was leading nowhere :-)

Show quoted text 9 lines
> willing to work on it. I did the bulk of the design and maintenance in > the past, I'll handle this as well. > So you can cooperate with me and propose solutions that I'm willing to implement > and spend time on, I see no workable solution at this moment. So I'll wait what you have to offer, and see if it matches my own. Otherwise I'll see if I can create some parallel bae library, but that has to wait till generics on FPC are more mature.

Fair enough.

Meanwhile you can help by supplying me with a test image file that takes too long to load. I recall you said something about seconds. Since all the ones I use load in acceptible times, I'd like to see one where things go badly wrong.

Michael.

Reply by email

Unknown author
to Florian Klämpfl: Am 22.04.2011 13:32, schrieb Speedwise it makes no difference. The difference is to have…
Florian Klämpfl wrote 25 lines
Am 22.04.2011 13:32, schrieb > > > On Fri, 22 Apr 2011, Florian Klämpfl wrote: > >>> (I suspect this is why it is possible to add type restrictions in the >>> Delphi/.Net implementations) >>> >>> 2. If I have my own overloaded version of '+' for a record, the above >>> means that it >>> cannot ever be used for generics, while it will be used for all my >>> other code. >>> >>> Say I define a type, and decide not to put the operators inside the >>> record, >>> for whatever reason. I am happily unaware of generics. Along comes an >>> afficiniado of generics, and wants to use my type in generics, but hits >>> the above problem. He is stuck. >> >> No. He can define a record helper operator. > > Which then simply repeats what I already had ? Very efficient :-) Speedwise it makes no difference. The difference is to have simple rules which symbols are defined during specialization.

I was not talking about speed efficiency :)

I understand the problem; However, I see no logical reason why you would 'see' a helper, when specializing, and 'not see' an operator which does the same. Both identifiers (thats what they are, deep down) are in scope at the time of specialization. If you can see the one, why not the other ?

There may be implementation difficulties for the operator, but then these should be solved.

Michael.

Reply by email

Unknown author
to Florian Klämpfl: I meant a semantical hybrid approach, not technical because Users want simply rules how…
Florian Klämpfl wrote 12 lines
Am 22.04.2011 12:58, schrieb Sven Barth: >> No. He can define a record helper operator. The question is simple: do >> we want generics behave like macros or more like .Net generics. Some >> hybrid approach is imo wrong. > > Before I forget it: Why do you think that a hybrid approach is wrong? I meant a semantical hybrid approach, not technical because Users want simply rules how things work. So the rule: "only symbols available during generic definition time are available during specialization" is a simple rule. Every exception like: but operators are available as well are hard to understand for a user.

By this rule, the helper class/operator/beast you proposed in the other mail should also not be available, because it is not known during definition.

Just as a helper is 'attached' to a type, an operator is equally 'attached' to the type. Both can be "attached" by a third party that requires it : all that is needed to use it is that it is in your current scope.

To me this means that if you allow the one, you should - logically - allow the other. (or vice versa)

that this probably presents implementation difficulties, and may require reworking of operator overloading, I readily believe; I'm just considering language design at the moment.

Michael.

Reply by email

Žilvinas Ledas
to Unknown author: No, they are "old" languages too. I was more thinking in terms of PHP, Ruby, Python,…
Show quoted text 19 lines
On Fri, 22 Apr 2011, Marco van de Voort wrote: > In our previous episode, said: >>> class for each storage type and deal with delegation overhead. >>> >>> I've complete understanding for the fact that generics are too >>> early, but >>> IMHO it is the long term solution. Anything else would be madness, >>> or minor >>> damage control at best. >> >> Most of the more "recent" or "new" languages I know do not have >> generics, > > What do you mean, C++,C#, Java ? No, they are "old" languages too. I was more thinking in terms of PHP, Ruby, Python, Javascript (and its variations). I haven't come accross generics for these languages. Yet they are widely adopted.

I don't think that either group could be caller "newer":

JAVA (1995): Sun Microsystems released the first public implementation as Java 1.0 in 1995 (James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991)
C++ (~1980): It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C language and originally named C with Classes. It was renamed C++ in 1983.[3]
C# (2000): By the time the .NET project was publicly announced at the July 2000 Professional Developers Conference, the language had been renamed C#, and the class libraries and ASP.NET runtime had been ported to C#.

PHP (1995): PHP was originally created by Rasmus Lerdorf in 1995 JavaScript (1995): LiveScript was the official name for the language when it first shipped in beta releases of Netscape Navigator 2.0 in September 1995, but it was renamed JavaScript in a joint announcement with Sun Microsystems on December 4, 1995
Ruby (1990): Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto. Python (1980-89): Python was conceived in the late 1980s [8] and its implementation was started in December 1989[9] by Guido van Rossum at CWI in the Netherlands

Regards
Žilvinas

Reply by email

Sven Barth
to Žilvinas Ledas
Žilvinas Ledas wrote 45 lines
On 2011-04-22 14:47, wrote: > On Fri, 22 Apr 2011, Marco van de Voort wrote: > >> In our previous episode, said: >>>> class for each storage type and deal with delegation overhead. >>>> >>>> I've complete understanding for the fact that generics are too >>>> early, but >>>> IMHO it is the long term solution. Anything else would be madness, >>>> or minor >>>> damage control at best. >>> >>> Most of the more "recent" or "new" languages I know do not have >>> generics, >> >> What do you mean, C++,C#, Java ? > > No, they are "old" languages too. I was more thinking in terms of PHP, > Ruby, Python, Javascript (and its variations). I haven't come accross > generics for these languages. Yet they are widely adopted. I don't think that either group could be caller "newer": JAVA (1995): Sun Microsystems released the first public implementation as Java 1.0 in 1995 (James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991) C++ (~1980): It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C language and originally named C with Classes. It was renamed C++ in 1983.[3] C# (2000): By the time the .NET project was publicly announced at the July 2000 Professional Developers Conference, the language had been renamed C#, and the class libraries and ASP.NET runtime had been ported to C#. PHP (1995): PHP was originally created by Rasmus Lerdorf in 1995 JavaScript (1995): LiveScript was the official name for the language when it first shipped in beta releases of Netscape Navigator 2.0 in September 1995, but it was renamed JavaScript in a joint announcement with Sun Microsystems on December 4, 1995 Ruby (1990): Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto. Python (1980-89): Python was conceived in the late 1980s [8] and its implementation was started in December 1989[9] by Guido van Rossum at CWI in the Netherlands

At least the last two were news to me O.o

Regards,
Sven

Reply by email

Florian Klämpfl
to Unknown author: By this rule, the helper class/operator/beast you proposed in the other mail should also…

Am 22.04.2011 14:01, schrieb

Show quoted text 9 lines
By this rule, the helper class/operator/beast you proposed in the other mail should also not be available, because it is not known during definition. Just as a helper is 'attached' to a type, an operator is equally 'attached' to the type. Both can be "attached" by a third party that requires it : all that is needed to use it is that it is in your current scope.

IMO a helper is bound closer to a type than an operator.

To me this means that if you allow the one, you should - logically - allow the other. (or vice versa)

With the same reasoning, one should allow also functions taking the type as parameter.

that this probably presents implementation difficulties,

Implementation is imo not the problem.

Reply by email

Jilani Khaldi
to Florian Klämpfl
{$linklib c}
uses
   dynlibs;
procedure hello(const x: double); cdecl; external 'libmylib.so';
var
   lHandle: TLibHandle;
   v: double;
begin
   lHandle := LoadLibrary('./libmylib.so');
   if lHandle  nilHandle then
   begin
     v := 3.14159;
     hello(v);
   end else
     writeln('Cannot load "mylib.so"')
end.

It is compiled without error but when I run it it throws: ./testlib: error while loading shared libraries: libmylib.so: cannot open shared object file: No such file or directory.

What I did I miss?.
Thank you.

Jilani KHALDI ** Architectura Vindex http://www.vindexa.org

Reply by email

Michael Van Canneyt
to Florian Klämpfl: Am 22.04.2011 14:01, schrieb IMO a helper is bound closer to a type than an operator.…
Florian Klämpfl wrote 12 lines
Am 22.04.2011 14:01, schrieb > > By this rule, the helper class/operator/beast you proposed in the other > mail > should also not be available, because it is not known during definition. > > Just as a helper is 'attached' to a type, an operator is equally > 'attached' to the type. Both can be "attached" by a third party that > requires it : all that is needed to use it is that it is in your current > scope. IMO a helper is bound closer to a type than an operator.

Please explain ? To my understanding, they're on exactly the same level ? (from a language feature point of view).

I mean, what can be more close to a type than a := operator ?
Show quoted text 6 lines
> To me this means that if you allow the one, you should - logically - > allow the other. > (or vice versa) With the same reasoning, one should allow also functions taking the type as parameter.

Functions are different, because they are not something you attach to a type. A function just happens to have one parameter (out of possibly many) of a particular type.

A class helper and operator are explicitly designed for this type, enhancing it to be able to work with it.

But that's beside the point:

I just think that if you except one and the other not, then that does not look like a very consequent application of generics, more like patchwork instead of a well integrated language feature.

I see no reason why you would prefer one language feature above another in such cases.

Michael.

Reply by email

Žilvinas Ledas
to Michael Van Canneyt
Michael Van Canneyt wrote 8 lines
> > IMO a helper is bound closer to a type than an operator. Please explain ? To my understanding, they're on exactly the same level ? (from a language feature point of view). I mean, what can be more close to a type than a := operator ?

From MY point of view operator is a (special) function, that takes (one/two/...) parameters and returns a result.
So I would agree that helper is "closer" than an operator.

Regards
Žilvinas Ledas

Reply by email

ik
to Jilani Khaldi: {$linklib c} uses dynlibs; procedure hello(const x: double); cdecl; external…
Jilani Khaldi wrote 26 lines
{$linklib c} uses dynlibs; procedure hello(const x: double); cdecl; external 'libmylib.so'; var lHandle: TLibHandle; v: double; begin lHandle := LoadLibrary('./libmylib.so'); if lHandle nilHandle then begin v := 3.14159; hello(v); end else writeln('Cannot load "mylib.so"') end. It is compiled without error but when I run it it throws: ./testlib: error while loading shared libraries: libmylib.so: cannot open shared object file: No such file or directory. What I did I miss?.

You do not have the library path on the system LD_LIBRARY_PATH variable or at the ldconfig path.

BTW, why don't you load it dynamically instead of statically if you are going the next mile to test it.
Your program will not be executed if the library is not found either way...

Show quoted text 10 lines
Thank you. -- Jilani KHALDI ** Architectura Vindex http://www.vindexa.org _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Ido

Reply by email

Jilani Khaldi
to ik
You do not have the library path on the system LD_LIBRARY_PATH variable or at the ldconfig path.

I have set it manually and it works. How to set it inside "fpc.cfg" file?

BTW, why don't you load it dynamically instead of statically if you are going the next mile to test it.

How to do this?
Thanks!

Jilani KHALDI --------------------- ** Architectura Vindex http://www.vindexa.org

Reply by email

Michael Van Canneyt
to Žilvinas Ledas: From MY point of view operator is a (special) function, that takes (one/two/...)…
Žilvinas Ledas wrote 13 lines
On 2011-04-22 20:05, Michael Van Canneyt wrote: >> >> IMO a helper is bound closer to a type than an operator. > > Please explain ? To my understanding, they're on exactly the same level ? > (from a language feature point of view). > > I mean, what can be more close to a type than a := operator ? From MY point of view operator is a (special) function, that takes (one/two/...) parameters and returns a result. So I would agree that helper is "closer" than an operator.

I suspect it's a highly indvidual matter.

What is "higher" or "Closer", functions or operators ? I would think functions, as they are evaluated first in an expression. Others may use different metrics...

The only objective way, I suppose, is to treat all constructs as on the same level.

Michael.

Reply by email

Sven Barth
to Jilani Khaldi: {$linklib c} uses dynlibs; procedure hello(const x: double); cdecl; external…
Jilani Khaldi wrote 20 lines
{$linklib c} uses dynlibs; procedure hello(const x: double); cdecl; external 'libmylib.so'; var lHandle: TLibHandle; v: double; begin lHandle := LoadLibrary('./libmylib.so'); if lHandle nilHandle then begin v := 3.14159; hello(v); end else writeln('Cannot load "mylib.so"') end.

You are mixing two different approaches here:

By using "external 'libmylib.so'" you tell the compiler to link the library at compiletime, so you can call "hello" without the "LoadLibrary".

For using LoadLibrary you need to follow a different approach:

===source begin===

type
   THelloProc = procedure(const x: Double); cdecl;
var
   hello: THelloProc;
   lHandle: TLibHandle;
begin
   lHandle := LoadLibrary('./libmylib.so');
   if lHandle  NilHandle then begin
     hello := THelloProc(GetProcAddress(lHandle, 'hello'));
     if not Assigned(hello) then
       Writeln('Cannot find ''hello'' function')
     else
       hello(3.14159);
   end else
     Writeln('Cannot load ''mylib.so''');
end.

===source end===

It is compiled without error but when I run it it throws: ./testlib: error while loading shared libraries: libmylib.so: cannot open shared object file: No such file or directory.

It might not be the LoadLibrary that fails, but the statically linked function. You need to add the path to your LD_LIBRARY_PATH and (to answer your second mail) no, you can't add this to fpc.cfg, because this is not a problem of the compiler, but of the runtime/the operating system. A linux system searches by default only in the directories that are mentioned in LD_LIBRARY_PATH for libraries.

What I did I miss?. Thank you.

Btw: You don't need to include "linklib c".

Regards,
Sven

Reply by email

Marco van de Voort
to Unknown author: No, they are "old" languages too. I was more thinking in terms of PHP, Ruby, Python,…

In our previous episode, said:

Show quoted text 10 lines
>>> IMHO it is the long term solution. Anything else would be madness, or minor >>> damage control at best. >> >> Most of the more "recent" or "new" languages I know do not have generics, > > What do you mean, C++,C#, Java ? No, they are "old" languages too. I was more thinking in terms of PHP, Ruby, Python, Javascript (and its variations). I haven't come accross generics for these languages. Yet they are widely adopted.

Ah, I don't considered those languages. At least not where any discussions about performance or efficiency apply ;_)

So, I'm afraid I'll have to bounce the earlier request to cut the retoric back to you.

Show quoted text 6 lines
> It eases some cases where that strictness hurts. There are multiple > solutions for such cases, e.g. in the database world, people went for > variants. I have a database with over 7000 fields, another with 3000, for neither variants are used. Maybe I misunderstand your statement.

The point was about that not every relaxation of the typed regime is generic based. It is about choosing the right relaxation for the right application.

.. or is your database layer entirely strong typed? If so, you might want to talk to Frank H. of GPC, he is afaik also strongly in favour of such approach. (and that is not meant in disrespectful way, though it is a bit a specialty IMHO)

> They are as subjective as a one person mandated ban on generics. Even long > term. Exactly, which is why the discussion was leading nowhere :-)

There never was a discussion. Apparently the result was preset. Not the healthies of principles btw. I counted in SVN btw, 20 commits for you, 17 for me in fcl-image, though several of mine will probably mostly touch makefiles and fpmake restructures.

> I see no workable solution at this moment. So I'll wait what you have to > offer, and see if it matches my own.

(and with these principles I'm 100% positive that it won't btw. This was more the hope that it will at least match enough to use it for secondary goals and/or recycle readers and writers with relative minimal efforts)

> Otherwise I'll see if I can create some > parallel base library, but that has to wait till generics on FPC are more > mature.

Where I should remark that even D/XE is borderline readiness atm.

Meanwhile you can help by supplying me with a test image file that takes too long to load. I recall you said something about seconds. Since all the ones I use load in acceptible times, I'd like to see one where things go badly wrong.

The next time I work on my libs, I'll do some testing and see if I can start building a lib of interesting cases. There are several bugs in mantis too btw, mostly dealing with alpha.

But IIRC it was converting 4096x7000x8bpp bmps to png. I was compressing our archive of BMPs, and used imgconv to provide a baseline to test my own png writing routines (a line based simplification of the current readers/writers) with.

I also have a vague recollection of some troubles with topdown images, probably 16-bit bmp grayscale, but can't remember the exact details.

Reply by email

Jilani Khaldi
to Sven Barth: You are mixing two different approaches here: By using "external 'libmylib.so'" you tell…
Sven Barth wrote 19 lines
On 22.04.2011 18:31, Jilani Khaldi wrote: > {$linklib c} > > uses > dynlibs; > > procedure hello(const x: double); cdecl; external 'libmylib.so'; > > var > lHandle: TLibHandle; > v: double; > begin > lHandle := LoadLibrary('./libmylib.so'); > if lHandle nilHandle then > begin > v := 3.14159; > hello(v); > end else > writeln('Cannot load "mylib.so"')

That's ok. It works now as expected.
Thank you :-)

Jilani KHALDI --------------------- ** Architectura Vindex http://www.vindexa.org

Reply by email

Michael Van Canneyt
to Marco van de Voort: In our previous episode, said: Ah, I don't considered those languages. At least not…
Marco van de Voort wrote 14 lines
In our previous episode, said: >>>> IMHO it is the long term solution. Anything else would be madness, or minor >>>> damage control at best. >>> >>> Most of the more "recent" or "new" languages I know do not have generics, >> >> What do you mean, C++,C#, Java ? > > No, they are "old" languages too. I was more thinking in terms of > PHP, Ruby, Python, Javascript (and its variations). I haven't come > accross generics for these languages. Yet they are widely adopted. Ah, I don't considered those languages. At least not where any discussions about performance or efficiency apply ;_)

The topic was the availability of generics.
In that field, all languages are viewed.

Show quoted text 14 lines
>> It eases some cases where that strictness hurts. There are multiple >> solutions for such cases, e.g. in the database world, people went for >> variants. > > I have a database with over 7000 fields, another with 3000, for neither > variants are used. Maybe I misunderstand your statement. The point was about that not every relaxation of the typed regime is generic based. It is about choosing the right relaxation for the right application. .. or is your database layer entirely strong typed? If so, you might want to talk to Frank H. of GPC, he is afaik also strongly in favour of such approach. (and that is not meant in disrespectful way, though it is a bit a specialty IMHO)

I don't know what you mean by 'strongly typed database layer', but the contents and type of each field is known. Elementary RDBMS and some level 3 normalization. No 'no sql' for me.

Show quoted text 7 lines
>> They are as subjective as a one person mandated ban on generics. Even long >> term. > > Exactly, which is why the discussion was leading nowhere :-) There never was a discussion. Apparently the result was preset.

You asked about my motivations, I gave them.

Not the healthies of principles btw. I counted in SVN btw, 20 commits for you, 17 for me in fcl-image, though several of mine will probably mostly touch makefiles and fpmake restructures.

Discarding initial design (there is no trace of that in SVN for obvious reasons), here is how I made my count:

home: >cd fpc/packages/fcl-image/src/
home: >foreach f ( *.* )
foreach? svn log $f >>log
foreach? end
home: >grep '^r' log | sort | uniq | wc -l
69
home: >grep '^r' log | sort | uniq | grep michael |wc -l 34
home: >grep '^r' log | sort | uniq | grep marco | wc -l 14

In each case, I think I have an approach which should speed things up, and still sticks to the design principles of fpImage.

I checked your code, and it throws overboard much if not all that fpImage was designed for. I'm aware that I'll probably never match what you had in speed terms, but then you made some very limiting design choices which I simply don't want in fpImage. The price of more generality is some speed loss, it is always so.

I would appreciate getting the really slow images if possible.

If there are still bugs in bottom-up images, I'd like to hear about them too, but they are an issue separate of the loading times issue; Probably a reader problem. As far as I know, bottom-up reading is supported for BMP.

Michael.

Reply by email

Marco van de Voort
to Michael Van Canneyt

In our previous episode, Michael Van Canneyt said:

Show quoted text 5 lines
> Ah, I don't considered those languages. At least not where any discussions > about performance or efficiency apply ;_) The topic was the availability of generics. In that field, all languages are viewed.

If you say so. Anyway, while I could try to create debate here (age of those languages, as confirmed by other reply, finding references about generics and generic-equivalent constructs in them), I'm not even interested enough in those languages to bother. At least not in FPC related language design context.

Show quoted text 8 lines
> .. or is your database layer entirely strong typed? If so, you might want to > talk to Frank H. of GPC, he is afaik also strongly in favour of such > approach. (and that is not meant in disrespectful way, though it is a bit a > specialty IMHO) I don't know what you mean by 'strongly typed database layer', but the contents and type of each field is known. Elementary RDBMS and some level 3 normalization. No 'no sql' for me.

Right. Should have said statically strong typed. Not related to RDBMS, but the lack of a generic db layer that requires runtime typing. Usually achieved by generating a lot of source with a preprocessor.

Because that was my point. Runtime typing (variants, array of const, idispatch) are IMHO more dangerous and against pascal principles than generics, which are still statically and strong typed.

From what I see I do realize generics generally do have a rather difficult

implementation. But we didn't hold back to the massive changes of the base Delphi dialect either, so that in itself is IMHO not enough reason to njet it.

Show quoted text 5 lines
>> Exactly, which is why the discussion was leading nowhere :-) > > There never was a discussion. Apparently the result was preset. You asked about my motivations, I gave them.

I haven't seen anything that has relevance in FPC context.

In each case, I think I have an approach which should speed things up, and still sticks to the design principles of fpImage.

The only design I see in fpimage is a general effort to try to support the costs.

And actually, back in the days, that was not a bad thing to have.

Show quoted text 5 lines
I checked your code, and it throws overboard much if not all that fpImage was designed for. I'm aware that I'll probably never match what you had in speed terms, but then you made some very limiting design choices which I simply don't want in fpImage. The price of more generality is some speed loss, it is always so.

I don't see the need for that. I just want to keep a handful of generic storage types very fast and seperately usable, just like we essentially have one storage type (64-bit RGBA) now. This for image manipulation.

Then expand the readers/writers to optionally operate rowbased, and have a few codepath simplifications in them (e.g. try to avoid the copying of rowdata to local arrays to facilitate compression and filtering in e.g. PNG if you don't use either), so that they essentially get zero-copy possibilities. I'm thinking about png, bmp and maybe jpg here.

This also has consequences for reader errorhandling, it should be possible to pass a 16-bit (e.g. RGB555) memory image to a reader, and have the reader throw an exception or terminate with errorcode if the pic to load requires something bigger. (or we need a "peek" approach, to first open the image and determine the format, then allocate to custom load the memory image, and only then load it).

Another annoying one that should be tackled whatever choice is made, is at least being able to override the compression level in the pngwriter. It is now always clmax which is IIRC the slowest way. (and for "photo" data, the gains are very small and not worth that).

All the rarer ones keep working on the 64-bit RGBA16 base type as it is now, pixel oriented etc. I planned to see if something could be done for them after the main restructuring.

A problem that I haven't thought up a solution for is autodetection of the format to safe. There have been mantis bugs about this (iirc one by Felipe), namely if you write an image you need to set options, and if you used canvas that might not be the same options as received from the image when read (e.g. a 257th color has been used, making palette impossible)

But all this is guesswork, since you don't detail the problems with my approach except that you won't use generics at work, and you haven't detailed your own more than that you plan to accelerate it (but not too much) and use delegation. And of course stick to a design philisophy that is detailed nowhere.

I put that crude intentionally. Since we are not going to concur at this point, it seems you'll go ahead, but I hope that it provides an incentive to be more open with it, and have some public resources. (there is a page for fcl-image in the wiki)

Show quoted text 5 lines
I would appreciate getting the really slow images if possible. If there are still bugs in bottom-up images, I'd like to hear about them too, but they are an issue separate of the loading times issue; Probably a reader problem. As far as I know, bottom-up reading is supported for BMP.

It's a while ago (early last summer), and a bit in fall when XE came out. But soon I'll be picking this up again.

Reply by email

Michael Van Canneyt
to Marco van de Voort
Marco van de Voort wrote 5 lines
> In each case, I think I have an approach which should speed things up, and > still sticks to the design principles of fpImage. The only design I see in fpimage is a general effort to try to support the costs.

Not "nevermind the costs". For example, the choice for 16 bits per channel was based on the assumption that in the future, most things will be 64-bit anyway. A complete color then fits in a register.
Speculative, yes, but I haven't seen anything yet which contradicts that assumption. In fact, Moore's law guarantees it.

And yes, I prefer to support everything, at the cost of speed. This is is a conscious design choice.

The compiler itself uses the same philosophy, I haven't heard you complain in that case. In fact, you argue for it when people complain about the compiler speed.

But equally like the compiler people, I do take speed issues to heart, and I will work on it.

Michael.

Reply by email