From: "bubble" <bubble@riskm.com.tw>
Subject: Re: function "&" for strings type cause memory problem.
Date: Fri, 11 Nov 2005 16:25:21 +0800
Date: 2005-11-11T16:25:21+08:00 [thread overview]
Message-ID: <dl1kho$t76$1@netnews.hinet.net> (raw)
In-Reply-To: dkv059$hit$1@netnews.hinet.net
dear all:
thank your reply.
correct me if I'm wrong.
maybe the subject should be
function "&" crash in thread's stack size is too small, even if you have a
big heap memory.
I knew to allocate a "large" object in stack is a bad idea.(another
question:how to define "large" to stack?)
and I allocate the large object in heap memory in previous case.
It's seem so beauty :)
if "&" is creating its result on the stack ,it still has potential risk.
in others.
I don't want to tell my programer:
" you can not use & for string or array,it has 1% probability to crash"
I want to say.
" & for string or array merge don't crash, but you will get worst
performace"
" you can change code and you will get better performance"
To Jeff and Dmitry.
in fact.
the the kernel(ada part) just crash "few" times.
It work perfectly until now after I change something like new test case .
my string are not so big,
I give you the extreme example.
because I just want to say bugs often happen in extreme case.
and I have not find any documents to increasing stack size in VB6.
please see new test case.
--------for test.adb-----------------------
with Ada.Text_IO;
Use Ada.Text_Io;
With stringFunctionPatch;
procedure test Is
Type Access_String Is Access String;
String1 : String := (1 .. 10_000_000 => 'a');
String2 : String := (1 .. 10_000_000 => 'b');
function "&" (Left,Right:string)Return String Renames
StringFunctionPatch."&"; --enable/disable the line
begin
declare
Nstring2 : access_string := null;
begin
Nstring2 := new String'(String1 & String2);
Put_Line("Test 2 Passed ");
end;
end test;
---------------------stringFunctionPatch.ads-------------------
package stringFunctionPatch is
Function "&"(Left,Right:string)Return String;
end stringFunctionPatch;
--------------------stringFunctionPatch.adb-------------------
with Ada.Finalization;
With Ada.Unchecked_Deallocation;
package body stringFunctionPatch is
type string_pointer is access String;
Procedure Free Is New Ada.Unchecked_Deallocation(String,String_Pointer);
type Buffer is new Ada.Finalization.Controlled with record
Data:string_pointer:=Null;
end record;
procedure Finalize (Object : in out Buffer) Is
Begin
Free(Object.Data);
End;
function "&" (Left, Right : String) return String Is
StringBuffer:Buffer;
Begin
Stringbuffer.Data:=New String (1 .. Left'Length + Right'Length);
Stringbuffer.Data.all (1 .. left'Last) := left;
Stringbuffer.Data.all ( Left'Last+1 .. Left'Last + Right'Last):=Right
;
return Stringbuffer.Data.all;
end "&";
end stringFunctionPatch;
next prev parent reply other threads:[~2005-11-11 8:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-10 8:25 function "&" for strings type cause memory problem bubble
2005-11-10 9:01 ` Alex R. Mosteo
2005-11-10 9:23 ` Dmitry A. Kazakov
2005-11-10 18:04 ` tmoran
2005-11-10 20:45 ` Jeffrey R. Carter
2005-11-11 8:25 ` bubble [this message]
2005-11-11 9:43 ` Dmitry A. Kazakov
2005-11-11 11:55 ` bubble
2005-11-11 13:45 ` Dmitry A. Kazakov
2005-12-01 0:18 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox