[fpc-pascal] parameter list declaration

2017-03-31 Thread Mr Bee via fpc-pascal
Hi all,
I'm looking for official reference for function/procedure parameter list 
declaration in Pascal. I found this: 
http://www.freepascal.org/docs-html/ref/refse91.html but I think it's not 
really clear, especially for newbie. For example, when exactly we need to 
use/put ; (semicolon) instead of , (comma) in parameter list. Compare that to 
official document from Delphi here: 
http://docwiki.embarcadero.com/RADStudio/Berlin/en/Parameters_(Delphi) which I 
think a bit more clear.
Well, of course I know that matter quite well. I'm just looking for official 
reference from FPC so it can be referred in an article or book.
Thank you.
Regards,
–Mr Bee
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Setting record values

2017-03-31 Thread Ryan Joseph
I’ve been using a design pattern in my code which I think is probably pretty 
stupid so I’d like to make sure. Assume I have a type like TPoint below and I 
want to set the value I’ll doing something like point := PointMake(x, y). How 
does the compiler handle this? It probably has to allocate some memory on the 
heap so shouldn’t I always be setting values using the alternative 
TPoint.SetPoint? It’s maybe not a big deal but it’s something I’d like to clear 
up if it’s inefficient.

function PointMake (_x, _y: integer): TPoint;
begin
  result.x := _x;
  result.y := _y;
end;

procedure TPoint.SetPoint (_x, _y: integer);
begin
  x := _x;
  y := _y;
end;

same outcome but which is more efficient?

1) point.SetPoint(x, y);

2) point := PointMake(x, y);


Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Array clearing

2017-03-31 Thread Ryan Joseph
As far as the compiler is concerned what’s the difference between clearing an 
array using a for-loop vs. FillChar? It seems like iterating the array would be 
slower but what does FillChar do exactly and is it faster? The primary concern 
here is that the memory originally allocated (using SetLength right?) remains 
in the same location.

var
  list: array of integer;

SetLength(list, 10);

for i := 0 to high(list) do
  list[i] := 0; 

FillChar(list[0], Length(list) * sizeof(integer), 0);


Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] String Constants and Source File Code Page (Cross-platform)

2017-03-31 Thread African Wild Dog
2017-03-31 15:43 GMT-03:00 Jonas Maebe :

>
> http://wiki.freepascal.org/FPC_Unicode_support#Source_file_codepage
> http://wiki.freepascal.org/FPC_Unicode_support#String_constants
>
>
Thank you!

Regards
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Questions About Constructors

2017-03-31 Thread Sven Barth via fpc-pascal
Am 31.03.2017 19:27 schrieb "African Wild Dog" :
>
> 2017-03-30 4:25 GMT-03:00 Michael Van Canneyt :
>>
>>
>>
>> On Thu, 30 Mar 2017, African Wild Dog wrote:
>>
>>> Hello,
>>>
>>> 1 - What happens if my constructor raise an exception? Is my destructor
>>> automatically called?
>>
>>
>> Yes.
>>
>>>
>>> 2 - Are the class fields automatically initialized to Default(T) just
like
>>> in Delphi?
>>
>>
>> Yes. The're zeroed out when the memory for the class is allocated.
>>
>
> Thanks for the clarification.
> I've issued #0031619  to add these details in the documentation.

Keep in mind however that the second behavior can be changed by overriding
TObject.NewInstance (the default implementation allocates the memory of the
class and zeroes it).

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] String Constants and Source File Code Page (Cross-platform)

2017-03-31 Thread Jonas Maebe

On 31/03/17 20:01, African Wild Dog wrote:

What is the recomended way to deal with string constants in units which
are shared in cross-platforms projects?

For example, i started a project in Linux, where the source code files
are saved in UTF-8. If i use theses files in Windows, the constants
aren't automatically converted to the system code-page. So, i am getting
wrong characters when i access theses constants in Windows.


http://wiki.freepascal.org/FPC_Unicode_support#Source_file_codepage
http://wiki.freepascal.org/FPC_Unicode_support#String_constants


Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] String Constants and Source File Code Page (Cross-platform)

2017-03-31 Thread African Wild Dog
Hello,

What is the recomended way to deal with string constants in units which are
shared in cross-platforms projects?

For example, i started a project in Linux, where the source code files are
saved in UTF-8. If i use theses files in Windows, the constants aren't
automatically converted to the system code-page. So, i am getting wrong
characters when i access theses constants in Windows.

Regards
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Questions About Constructors

2017-03-31 Thread African Wild Dog
2017-03-30 4:25 GMT-03:00 Michael Van Canneyt :

>
>
> On Thu, 30 Mar 2017, African Wild Dog wrote:
>
> Hello,
>>
>> 1 - What happens if my constructor raise an exception? Is my destructor
>> automatically called?
>>
>
> Yes.
>
>
>> 2 - Are the class fields automatically initialized to Default(T) just like
>> in Delphi?
>>
>
> Yes. The're zeroed out when the memory for the class is allocated.
>
>
Thanks for the clarification.
I've issued # 0031619
  to add these details in the
documentation.


Best regards
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Call function in shared library from multiple threads

2017-03-31 Thread silvioprog
On Fri, Mar 31, 2017 at 1:15 PM, Henry Vermaak 
wrote:

> On Fri, Mar 31, 2017 at 08:42:24AM -0700, fredvs wrote:
> > > Z:\home\fred\uos\examples\uos.pas(7438,29) Warning: (4046)
> Constructing a
> > > class "TThread" with abstract method "Execute"
> >
> > Huh, is it Is it serious doctor?
>
> I use this:
>
> function DummyThread(param: pointer): ptrint;
> begin
>   Result := 0;
>   EndThread(Result);
> end;
>
> begin
>   BeginThread(@DummyThread);
>   ...
>   ...
> end.


What about calling TM directly? Something like this:

uses cthreads;
var
  TM: TThreadManager;
begin
  TM := Default(TThreadManager); // just hiding hint 'variable TM doesn't
seem to be initialized'
  GetThreadManager(TM);
  IsMultiThread := TM.InitManager;
...
end.

I can't test it now (I would like to debug it asap), but I think FPC offer
some option to start the TM without starting a new -- dummy -- thread. o.O

-- 
Silvio Clécio
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Call function in shared library from multiple threads

2017-03-31 Thread fredvs
Michael Van Canneyt wrote
> Best is probably:
> 
> Type
>TDummyThread = Class(TThread)
>public
>  procedure execute; override;
>end;
> 
> procedure TDummyThread.Execute;
> 
> begin
>FreeOnTerminate:=True;
>Terminate;
> end;
> 
> 
> begin
>TDummyThread.Create(True)
> end.


OK, perfect, no more warning, thanks doctor. 

Fre;D



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Call-function-in-shared-library-from-multiple-threads-tp5728035p5728060.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Call function in shared library from multiple threads

2017-03-31 Thread Henry Vermaak
On Fri, Mar 31, 2017 at 08:42:24AM -0700, fredvs wrote:
> > Z:\home\fred\uos\examples\uos.pas(7438,29) Warning: (4046) Constructing a
> > class "TThread" with abstract method "Execute"
> 
> Huh, is it Is it serious doctor?

I use this:

function DummyThread(param: pointer): ptrint;
begin
  Result := 0;
  EndThread(Result);
end;

begin
  BeginThread(@DummyThread);
  ...
  ...
end.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Call function in shared library from multiple threads

2017-03-31 Thread Michael Van Canneyt



On Fri, 31 Mar 2017, fredvs wrote:


Hello.


Michael Van Canneyt wrote
To fix that, you can do the following. 
In the library startup code, create a dummy thread. 
This will initialize the threads mechanism:


   with TThread.Create(False) do

end.


I use this for initialize my libraries:



Best is probably:

Type
  TDummyThread = Class(TThread)
  public
procedure execute; override;
  end;

procedure TDummyThread.Execute;

begin
  FreeOnTerminate:=True;
  Terminate;
end;


begin
  TDummyThread.Create(True)
end.


Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Call function in shared library from multiple threads

2017-03-31 Thread fredvs
Hello.


Michael Van Canneyt wrote
> To fix that, you can do the following. 
> In the library startup code, create a dummy thread. 
> This will initialize the threads mechanism:
> 
>with TThread.Create(False) do
> 
> end.

I use this for initialize my libraries:

 With TThread.Create(False) do Terminate;

It works ok but there is that warning after compiling:


> Z:\home\fred\uos\examples\uos.pas(7438,29) Warning: (4046) Constructing a
> class "TThread" with abstract method "Execute"

Huh, is it Is it serious doctor?

Fre;D





-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Call-function-in-shared-library-from-multiple-threads-tp5728035p5728057.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Call function in shared library from multiple threads

2017-03-31 Thread Krzysztof
Thanks a lot! Seems to working fine now
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Error on closing application when using a library.

2017-03-31 Thread fredvs
Hello.

Once again, fpc has nothing to do with that problem.

See here:
https://www.kapilarya.com/this-application-has-requested-the-runtime-to-terminate-it-in-an-unusual-way-windows-10

Ok, (grrr...), I will follow this notice.

PS: If I may, I find strange that Microsoft cannot make libraries (or
applications) run correctly that was compiled with a Microsoft compiler
(VS).

PS2: I have libraries compiled with fpc, 10 years old, and that run
perfectly on XP -> Win 10.

PS3: Please, fpc team, do not forget libraries (and, f possible, do
something to reduce the size).

Fre;D
 



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Error-on-closing-application-when-using-a-library-tp5728045p5728055.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Call function in shared library from multiple threads

2017-03-31 Thread Michael Van Canneyt



On Thu, 30 Mar 2017, Michael Van Canneyt wrote:




On Thu, 30 Mar 2017, Krzysztof wrote:


2017-03-30 15:19 GMT+02:00 Michael Van Canneyt 



Nevertheless, that should work.

I've used it in multi-threaded apache modules.



Well it doesn't work or fpjson module is not thread safe in this case. You
can test it by yourself with attached demo (first post). Try it few times
because sometimes if you are lucky then there is no error


If I find a moment, I will test.


I can reproduce the problem.

At least partially it is related to the threads mechanism not being initialized
correctly.

To fix that, you can do the following. 
In the library startup code, create a dummy thread. 
This will initialize the threads mechanism:


library testlib;

{$mode objfpc}{$H+}

uses
  cthreads, cmem, Classes, testlibu;

exports
  InitTest, FinalizeTest, Test;


begin
  with TThread.Create(False) do

end.


After this, I no longer get the problem (which doesn't mean there are no
other possible problems :) )

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-31 Thread Ryan Joseph

> On Mar 31, 2017, at 3:55 PM, Gary Doades  wrote:
> 
> However, multiple independent compute units must be required for *true* 
> parallelism. On a single processor any tasks running at the same time is just 
> an illusion, normally created by the OS in time slicing between tasks based 
> on certain criteria (priority, I/O, cpu usage etc.). That applies equally to 
> threads or processes

Yeah exactly. Even if those are nodes on a network you need more than one. 
Unless you're making a bot-net or software designed for specific hardward which 
is known to have multiple cores, parallelism probably means using the GPU via 
an API like OpenCL, which is far cry from threading some tasks to run async.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-31 Thread Ryan Joseph

> On Mar 31, 2017, at 4:38 PM, Tony Whyman  
> wrote:
> 
> For example, this distinction is very important in matrix algorithms. When 
> operating on two matrices to produce another, the operations on each cell can 
> be identified as n x m parallel actions at design time. At deployment time, 
> it is often desirable to have a scalable implementation that can use anything 
> from 1 to n x m processors to do the job. Thus you can have a design that 
> identifies parallelism leading to an implementation that can non-parallel, 
> partly or wholly parallel (in real time) depending on the size of the 
> matrices and the number of processors available. 

That’s a good candidate for parallelism but you need an API like OpenCL to 
implement it properly so you can access the actual hardware required. From the 
little time I spent with OpenCL you really don’t want to (or shouldn’t) be 
intentionally designing your programs like this unless you have a real need for 
“true” parallelism with multiple compute units.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-31 Thread Tony Whyman


On 31/03/17 09:55, Gary Doades wrote:

However, multiple independent compute units must be required for*true*  
parallelism. On a single processor any tasks running at the same time is just 
an illusion, normally created by the OS in time slicing between tasks based on 
certain criteria (priority, I/O, cpu usage etc.). That applies equally to 
threads or processes
I think that what are referring to here is not so much *true* 
parallelism but that when parallelism is designed into an application, 
it enables real time parallel computing when the application is deployed.


For example, this distinction is very important in matrix algorithms. 
When operating on two matrices to produce another, the operations on 
each cell can be identified as n x m parallel actions at design time. At 
deployment time, it is often desirable to have a scalable implementation 
that can use anything from 1 to n x m processors to do the job. Thus you 
can have a design that identifies parallelism leading to an 
implementation that can non-parallel, partly or wholly parallel (in real 
time) depending on the size of the matrices and the number of processors 
available.


At what point does this become *true* parallelism?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-31 Thread Gary Doades
> I would offer the following definitions:

> - Parallelism is a (design) concept for expressing collateral actions in 
> which the processing order of the actions is unspecified. They may take place 
> serially or 
> contemporaneously in real time, or a mixture of the two.

> - Threads are an implementation mechanism for realising collateral actions 
> within a single processing environment.

> Neither of the above implies multiple CPUs or processing units.

I would agree wholeheartedly with most of that. Parallelism is purely a concept 
of multiple tasks running at the same time

Threads or processes are just implementations of that concept. Threads tend to 
be used for related tasks in a single process. Separate processes tend to be 
used for unrelated or independent tasks. Those are not hard and fast rules.

However, multiple independent compute units must be required for *true* 
parallelism. On a single processor any tasks running at the same time is just 
an illusion, normally created by the OS in time slicing between tasks based on 
certain criteria (priority, I/O, cpu usage etc.). That applies equally to 
threads or processes

Various languages assist, or purely exist, to make creating multi-tasking 
easier, but it ultimately all boils down to the same thing.

Regards,
Gary


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-31 Thread Tony Whyman
The problem I have with this thread (no pun intended) is that it is not 
comparing like with like. As demonstrated by many of the replies, 
Parallelism and Threads are not the same thing.


I would offer the following definitions:

- Parallelism is a (design) concept for expressing collateral actions in 
which the processing order of the actions is unspecified. They may take 
place serially or contemporaneously in real time, or a mixture of the two.


- Threads are an implementation mechanism for realising collateral 
actions within a single processing environment.


Neither of the above implies multiple CPUs or processing units.


On 31/03/17 07:43, Ryan Joseph wrote:

On Mar 30, 2017, at 3:06 PM, Michael Schnell  wrote:


Huh, ok, but why parallelism is better and how to do it with fpc ?


Parallelism within a process always is based on threads.

AFAIK, fpc does not (yet) provide a more convenient abstraction for parallelism 
(such as parallel loops) than TThread.

-Michael

It’s my understanding that for parallelism to make sense you need to have at 
least more than 1 separate compute unit, be that a CPU core or a GPU.

If you had a GPU with 250 compute units or a CPU with 250 cores you would need 
to design your task in a way so that it could be broken down into as many 
discrete portions as possible so that you could take advantage of the multiple 
cores running in parallel. Even if you didn’t have a single thread and the 
execution blocked until finished you wouldn’t see any performance increases 
unless you designed your program to scale for parallelism. Running 250 threads 
on a single core isn’t going to be 250x faster but running 250 threads on 250 
cores may be.


Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] SPARC / Linux

2017-03-31 Thread Mark Morgan Lloyd

On 13/03/17 09:00, Pierre Free Pascal wrote:

-Message d'origine-> De : fpc-pascal [mailto:fpc-pascal-boun...@lists.freepascal.org] De la> part de Mark Morgan 
Lloyd> Envoyé : lundi 13 mars 2017 09:11> À : fpc-pascal@lists.freepascal.org> Objet : Re: [fpc-pascal] SPARC / 
Linux> > On 13/03/17 06:30, Pierre Free Pascal wrote:> > Hi Mark,> > if you mean build a native installer for 
32-btsparc-linux, I can tell> you want you need to do:> > I'm used to building it for my own use. I'll take a look at 
your> instructions for versions later than 2.6.2, since even getting 2.6.4 or> 3.0.0 available would be progress. Time 
permitting :-(

  I would also be interested in those other versions,if you succeed in building them. > > a 
libgdb installation to enable GDB inside FP IDE,which (if you do> not have> > I've found 
libgdb to be a problem on several platforms, it's not> maintained actively.You are breaking my 
heart...I am trying to maintain the internal GDB support for FP IDE,but even if I am a member of 
the GDB maintainer team,this is a huge task, which I never really have time to fulfill.
  I have no access to any sparc machine, thus it is even moredifficult to 
maintain such targets.


Appears that 3.0.2 builds on SPARC Linux with GDB607. I'm continuing to 
work on various combinations when time permits.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-31 Thread Ryan Joseph

> On Mar 30, 2017, at 3:06 PM, Michael Schnell  wrote:
> 
>> 
>> Huh, ok, but why parallelism is better and how to do it with fpc ?
>> 
> Parallelism within a process always is based on threads.
> 
> AFAIK, fpc does not (yet) provide a more convenient abstraction for 
> parallelism (such as parallel loops) than TThread.
> 
> -Michael

It’s my understanding that for parallelism to make sense you need to have at 
least more than 1 separate compute unit, be that a CPU core or a GPU.

If you had a GPU with 250 compute units or a CPU with 250 cores you would need 
to design your task in a way so that it could be broken down into as many 
discrete portions as possible so that you could take advantage of the multiple 
cores running in parallel. Even if you didn’t have a single thread and the 
execution blocked until finished you wouldn’t see any performance increases 
unless you designed your program to scale for parallelism. Running 250 threads 
on a single core isn’t going to be 250x faster but running 250 threads on 250 
cores may be. 


Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-31 Thread Michael Schnell

On 29.03.2017 20:57, fredvs wrote:


Huh, ok, but why parallelism is better and how to do it with fpc ?


Parallelism within a process always is based on threads.

AFAIK, fpc does not (yet) provide a more convenient abstraction for 
parallelism (such as parallel loops) than TThread.


-Michael

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal