Recent

Author Topic: String memory doubt  (Read 1879 times)

damieiro

  • Full Member
  • ***
  • Posts: 200
String memory doubt
« on: September 22, 2018, 01:57:51 pm »
Hi!

I'm making a memory manager that does bookeeping of callings to getmen and freemem (and their variants) to have a rough idea that a program has no memory leaks.
In my testings i have an strange result, and i do not know why.

If a procedure (or function) uses a string internally and calls other procedure (not in the same unit) using the string, that string doesn't call freemem
Example:

Compiler uses freemem for s3;

Code: Pascal  [Select][+][-]
  1. procedure SumStrings (s1,s2:string);
  2. Var
  3. s3:string;
  4.  
  5. begin
  6.   s3:=s1+s2;
  7.   writeln (s3);
  8. end;
  9. {compiler do it ok}
  10.  


Compiler doesn't seems to use freemen for s3 after ending procedure.
Code: Pascal  [Select][+][-]
  1. procedure SumStrings (s1,s2:string);
  2. Var
  3.   s3:string;
  4.  
  5. begin
  6.   s3:=s1+s2;  
  7.   writeln (s3);
  8.   {AnotherProcedure belongs to other unit}
  9.   AnotherProcedure (s3); {s3 is not removed with freemem, perhaps compiler does it other way}
  10. end;
  11.  
  12.  

(Note: updated post..).
« Last Edit: September 22, 2018, 08:32:30 pm by damieiro »

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: String memory doubt
« Reply #1 on: September 22, 2018, 04:21:55 pm »
For understanding, show the source code.

damieiro

  • Full Member
  • ***
  • Posts: 200
Re: String memory doubt
« Reply #2 on: September 22, 2018, 05:20:06 pm »
Aserge, I have edited first post to explain it better.

well, it's hard to put all code here... I'm interposing a memory manager to do the bookeeping. Basically traps when a getmen/freemen/allocmen (etc..) is done and bookeeps it. It would need to upload several files. These are in spanish..

But it can be (perfectly) a bug of mine.. I'm still testing...



« Last Edit: September 22, 2018, 09:08:35 pm by damieiro »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: String memory doubt
« Reply #3 on: September 22, 2018, 09:24:42 pm »
A simple test on my side showed no problems with that. So if in doubt I'd say that the problem is in your memory manager...

Also why do you write your own memory manager for that if you could simply use the one already provided by FPC? Simply compile your code with -gh and the compiler will insert its own heap tracing memory manager.

damieiro

  • Full Member
  • ***
  • Posts: 200
Re: String memory doubt
« Reply #4 on: September 22, 2018, 10:47:12 pm »
Well, i prefer my way :D. I have other philosophy for memory manager. When it's finished, then i will post it for comments :).

I have been testing. And yes, it seems a problem with my own manager passing arguments :). Fixed.

thx :)



 

TinyPortal © 2005-2018