Reputation: 83
Hi everyone ,
type String is array (Positive range <>) of Character;
Ok but , where is the limit when we declare a variable ?
When we do this :
max_String : String( 1 .. integer'last ) ;
It failed .
For instance :
With Ada.Text_IO ; Use Ada.Text_IO ;
Procedure fixed is
max_String : String( 1 .. integer'last ) ;
begin
get ( max_String ) ;
put ( max_String ) ;
End fixed ;
Compilator : " fixed.adb:3:1: error: total size of local objects too large "
Thanks.
Upvotes: 0
Views: 608
Reputation: 6601
Objects declared in a declarative block are allocated on the stack of the task they are running in.
This means that the limit is derived from how much stack space your operating system gives the program, when you run it.
I use Zsh on Linux, where I can check/adjust the assigned stack size with the command limit stacksize
:
% limit stacksize
stacksize 8MB
%
I can also change it:
% limit stacksize 2100m
% limit stacksize
stacksize 2100MB
%
If I started your program at this point (from the same shell), it might work fine.
Upvotes: 1
Reputation: 25491
When you create a string, it has the length you specify. So
S : String (1 .. 5);
reserves space for 5 characters.
L : String := “foo”;
reserves space for 3 characters and fills it with ‘f’, ‘o’, ‘o’.
Integer’Last
is about 2 billion; I don’t think you have that much RAM!
You probably want to use the function version of Ada.Text_IO.Get_Line
:
with Ada.Text_IO; use Ada.Text_IO;
procedure Fixed is
S : constant String := Get_Line;
begin
Put_Line (S);
end Fixed;
This initializes S
with whatever the first input line happens to be.
Most people who have to deal with strings use Unbounded_Strings
(needs a link - the ARM website is down at the moment)
Upvotes: 2