From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,23ace43a488fab29 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!Spring.edu.tw!news.nctu.edu.tw!feeder.seed.net.tw!netnews!not-for-mail From: "bubble" Newsgroups: comp.lang.ada Subject: Re: function "&" for strings type cause memory problem. Date: Fri, 11 Nov 2005 16:25:21 +0800 Organization: HiNetNews Message-ID: References: NNTP-Posting-Host: 211-21-128-195.hinet-ip.hinet.net X-Trace: netnews.hinet.net 1131697528 29926 211.21.128.195 (11 Nov 2005 08:25:28 GMT) X-Complaints-To: usenet@HiNetnews.hinet.net NNTP-Posting-Date: Fri, 11 Nov 2005 08:25:28 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2527 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 Xref: g2news1.google.com comp.lang.ada:6340 Date: 2005-11-11T16:25:21+08:00 List-Id: 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;