Maurice Lombardi wrote:
I am assuming the 'new' function doesn't explicitly zero memory and so I need to do. I have used this zero function on all the usual Pascal variables without problem, but I suspect it has a strange effect when used to zero a record containing a string. Can anyone confirm whether there are particular Pascal structures that shouldn't be zeroed by this technique (apart from dynamic arrays)?
Any kind of schemata, which include dynamic arrays ans strings
Also files and objects.
There is a built-in procedure `Initialize' to (re-)initialize any variable, so you could theoretically zero out everything, then initialize it again, but I'm not sure if I should have mentioned this. ;-) In any case, you'll do some extra work (init, zero, init again) ...
Silvio a Beccara wrote:
Don't you think the problem is in using a recursive function to zero arrays instead of a simple for-end cycle?
It's not recursive. `asmname' implies external (at least for now ...). (And, BTW, this procedure is equivalent to the built-in `FillChar', except for the order of arguments.)
But I agree, in this case I'd recommend a `for' loop, too.
| > PROCEDURE zero(VAR param; ch : char; size : longint); asmname 'memset'; | > | > BEGIN | > NEW( Test1, a ); | > writeln(sizeof(Test1^)); | > zero(Test1^,#0,sizeof(Test1^)); | > NEW( Test2, b ); | > writeln(sizeof(Test2^)); | > zero(Test2^,#0,sizeof(Test2^)); | > | > writeln(sizeof(Test1a)); | > zero(Test1a,#0,sizeof(Test1a)); | > writeln(sizeof(Test2a)); | > zero(Test2a,#0,sizeof(Test2a)); | > END.
Frank