Recent

Author Topic: Lazarus IDE with Cmem  (Read 982 times)

julkas

  • Sr. Member
  • ****
  • Posts: 382
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
Re: Lazarus IDE with Cmem
« Reply #15 on: August 15, 2019, 12:56:08 pm »
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7432
Re: Lazarus IDE with Cmem
« Reply #16 on: August 15, 2019, 01:09:54 pm »
That code runs on Linux, where it is somewhat more standard.

Cmem on Windows is ambiguous by default, since MSVC is the system C compiler, but FPC is mostly compatible with GCC (which again comes in many flavours like cygwin and mingw on Windows). And with many C compiler flavours come many C compiler runtimes.

julkas

  • Sr. Member
  • ****
  • Posts: 382
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
Re: Lazarus IDE with Cmem
« Reply #17 on: August 15, 2019, 01:19:39 pm »
Quote
That code runs on Linux, where it is somewhat more standard.
That code runs not only on Linux
Code: Pascal  [Select]
  1. {$IFDEF UNIX}CThreads,{$ENDIF}
I have tested that code on Win32 Vista.
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

Thaddy

  • Hero Member
  • *****
  • Posts: 8880
Re: Lazarus IDE with Cmem
« Reply #18 on: August 15, 2019, 01:30:41 pm »
Yes, but the point is the actual memory aloc/de-alloc implementation of the C compiler you used.
E.g. with other such "tests" on Raspbian and Debian arm I get much differing results between cmem and the default memory manager with GNU C for armhf.
cmem runs out of memory sooner because of the page size. Other C compilers for ARM do have a noticable effect (the one from ARM itself is a good example).
It depends on application., likely even the type of C libraries you interface with if it has any positive impact at all.
Also note the FPC default settings are extremely conservative compared to C compilers, so you may want to explore the optimization options first:
Alignment, CPU settings, optimization -O settings and even the FPU, e.g. vector math for moves is not used in default fpc. But all these things may have been done in a C version for you and they are not done for you in FPC.
Also note the LLVM back-end can improve things. And furthermore, at least on Intel, there are third-party open source Delphi memory managers that outperform both cmem and the fpc default by several magnitudes in a mutithreading application. These memory managers are easily adapted to Freepascal. There are several real - solid - performance tests available for those memory managers in which cmem is also tested and comes second from last. Memory use can be explosive with cmem, whereas fragmentation is an issue with the FPC default, both when stressed.
The delphi ones I mentioned all have per thread allocators, btw. Cmem does not do that, at least not with the GCC compiler.

One thing to note: in the compiler shoot-out (even with an older fpc) the fpc default memory allocator performs best in memory use offset to others that favor speed at the cost of memory.
But then again: memory managers are pluggable in FPC.
« Last Edit: August 15, 2019, 01:53:29 pm by Thaddy »
Most people that want to use threading should learn to patch their jeans first: use a needle.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7432
Re: Lazarus IDE with Cmem
« Reply #19 on: August 15, 2019, 02:45:53 pm »
Quote
That code runs on Linux, where it is somewhat more standard.
That code runs not only on Linux
Code: Pascal  [Select]
  1. {$IFDEF UNIX}CThreads,{$ENDIF}
I have tested that code on Win32 Vista.

That is part of a standard new program template. Not necessarily a sign it was prepared to run on windows.

Thaddy

  • Hero Member
  • *****
  • Posts: 8880
Re: Lazarus IDE with Cmem
« Reply #20 on: August 16, 2019, 09:40:24 pm »
And the answer to OP is: Yes I did tried your example and gave you the answer.
Most people that want to use threading should learn to patch their jeans first: use a needle.