comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: function "&" for strings type cause memory problem.
Date: Fri, 11 Nov 2005 10:43:00 +0100
Date: 2005-11-11T10:43:00+01:00	[thread overview]
Message-ID: <1fxvr41a6cj64$.1cin7p2ro7ua2$.dlg@40tude.net> (raw)
In-Reply-To: dl1kho$t76$1@netnews.hinet.net

On Fri, 11 Nov 2005 16:25:21 +0800, bubble wrote:

> 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?)

Let Si be a set of all objects simultaneously existing in the program P at
its execution state i. Si/|Si| is an average object size. Calculate its
expectation value for all possible states i=1..N. Now if the object's size
deviates from that in more than 3 sigma, the object is called "large".
(:-))

> 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.

Memory allocation is always a risk. An important objective of software
design is to minimize risks. One can ignore allocation issues as long as
objects are small. Otherwise some static analysis is required to ensure
that in any case the memory pool will be large enough to hold all objects.
There is no difference between stack and heap here. Even if, for example,
the heap can be enlarged on demand while the stack not, it is all OS
specific issue.

> 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"

Actually Ada provides 3 types of strings reflecting different memory
management strategies. Reconsider your design. For example, if objects are
large, then you need to drop that nice "functional programming" style, and
switch to hard core in-place operations. That is "Append" instead of "&".
You can also move the burden of allocation to the caller side, which
usually knows it better.

BTW, this is what Microsoft did with you. You are required to specify the
stack size. If something goes wrong, then your program will crash, instead
of showing some worse performance. There will be no any performance.

Basically, you have to decide who is responsible for what.

> 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.

Well, should it be Visual Basic? OK, you need not answer this! (:-))

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2005-11-11  9:43 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
2005-11-11  9:43   ` Dmitry A. Kazakov [this message]
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