all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
3
Task/Variable-size-Get/0DESCRIPTION
Normal file
3
Task/Variable-size-Get/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Demonstrate how to get the size of a variable.
|
||||
|
||||
See also: [[Host introspection]]
|
||||
2
Task/Variable-size-Get/1META.yaml
Normal file
2
Task/Variable-size-Get/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Type System
|
||||
7
Task/Variable-size-Get/ALGOL-68/variable-size-get.alg
Normal file
7
Task/Variable-size-Get/ALGOL-68/variable-size-get.alg
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
INT i; BYTES b; # typically INT and BYTES are the same size #
|
||||
STRING s:="DCLXVI", [666]CHAR c;
|
||||
print((
|
||||
"sizeof INT i =",bytes width, new line,
|
||||
"UPB STRING s =",UPB s, new line,
|
||||
"UPB []CHAR c =",UPB c, new line
|
||||
))
|
||||
2
Task/Variable-size-Get/Ada/variable-size-get.ada
Normal file
2
Task/Variable-size-Get/Ada/variable-size-get.ada
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Int_Bits : constant Integer := Integer'size;
|
||||
Whole_Bytes : constant Integer := Int_Bits / Storage_Unit; -- Storage_Unit is the number of bits per storage element
|
||||
2
Task/Variable-size-Get/AutoHotkey/variable-size-get.ahk
Normal file
2
Task/Variable-size-Get/AutoHotkey/variable-size-get.ahk
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
VarSetCapacity(Var, 10240000) ; allocate 10 megabytes
|
||||
MsgBox % size := VarSetCapacity(Var) ; 10240000
|
||||
2
Task/Variable-size-Get/BASIC/variable-size-get-1.basic
Normal file
2
Task/Variable-size-Get/BASIC/variable-size-get-1.basic
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
10 REM this only works with strings
|
||||
20 PRINT LEN(variable$)
|
||||
2
Task/Variable-size-Get/BASIC/variable-size-get-2.basic
Normal file
2
Task/Variable-size-Get/BASIC/variable-size-get-2.basic
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
DIM a AS INTEGER, b AS LONG, c AS SINGLE, d AS DOUBLE, e AS STRING
|
||||
PRINT LEN(a), LEN(b), LEN(c), LEN(d), LEN(e)
|
||||
11
Task/Variable-size-Get/BBC-BASIC/variable-size-get.bbc
Normal file
11
Task/Variable-size-Get/BBC-BASIC/variable-size-get.bbc
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
DIM bstruct{b&}
|
||||
DIM istruct{i%}
|
||||
DIM fstruct{f}
|
||||
DIM dstruct{d#}
|
||||
DIM sstruct{s$}
|
||||
|
||||
PRINT "Size of b& is ";DIM(bstruct{})
|
||||
PRINT "Size of i% is ";DIM(istruct{})
|
||||
PRINT "Size of f is ";DIM(fstruct{})
|
||||
PRINT "Size of d# is ";DIM(dstruct{})
|
||||
PRINT "Size of s$ is ";DIM(sstruct{})
|
||||
20
Task/Variable-size-Get/Babel/variable-size-get-1.pb
Normal file
20
Task/Variable-size-Get/Babel/variable-size-get-1.pb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
main:
|
||||
{ (1 2 (3 4) 5 6)
|
||||
dup mu disp
|
||||
dup nva disp
|
||||
dup npt disp
|
||||
dup nlf disp
|
||||
dup nin disp
|
||||
dup nhref disp
|
||||
dup nhword disp }
|
||||
|
||||
disp! : { %d cr << }
|
||||
|
||||
Output:
|
||||
38
|
||||
6
|
||||
14
|
||||
6
|
||||
7
|
||||
1
|
||||
4
|
||||
3
Task/Variable-size-Get/Babel/variable-size-get-2.pb
Normal file
3
Task/Variable-size-Get/Babel/variable-size-get-2.pb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
main : { (1 2 (3 4) 5 6) unload size %d << }
|
||||
Output:
|
||||
38
|
||||
2
Task/Variable-size-Get/C++/variable-size-get-1.cpp
Normal file
2
Task/Variable-size-Get/C++/variable-size-get-1.cpp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#include <cstdlib>
|
||||
std::size_t intsize = sizeof(int);
|
||||
3
Task/Variable-size-Get/C++/variable-size-get-2.cpp
Normal file
3
Task/Variable-size-Get/C++/variable-size-get-2.cpp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#include <climits>
|
||||
#include <cstdlib>
|
||||
std::size_t intbits = CHAR_BITS*sizeof(int);
|
||||
3
Task/Variable-size-Get/C++/variable-size-get-3.cpp
Normal file
3
Task/Variable-size-Get/C++/variable-size-get-3.cpp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#include <cstdlib>
|
||||
int a = 1;
|
||||
std::size_t a_size = sizeof a;
|
||||
2
Task/Variable-size-Get/C++/variable-size-get-4.cpp
Normal file
2
Task/Variable-size-Get/C++/variable-size-get-4.cpp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#include <cstdlib>
|
||||
std::size_t size = sizeof (3*6 + 7.5);
|
||||
1
Task/Variable-size-Get/C/variable-size-get.c
Normal file
1
Task/Variable-size-Get/C/variable-size-get.c
Normal file
|
|
@ -0,0 +1 @@
|
|||
printf("An int contains %u bytes.\n", sizeof(int));
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(let ((a (cons 1 2))
|
||||
(b (make-array 10))
|
||||
(c "a string"))
|
||||
(list (hcl:find-object-size a)
|
||||
(hcl:find-object-size b)
|
||||
(hcl:find-object-size c)))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(12 48 24)
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
(let (items)
|
||||
(gc) ; name varies by implementation
|
||||
(room)
|
||||
(dotimes (x 512)
|
||||
(push (allocate-something-of-interest) items))
|
||||
(gc)
|
||||
(room))
|
||||
7
Task/Variable-size-Get/D/variable-size-get.d
Normal file
7
Task/Variable-size-Get/D/variable-size-get.d
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
int i ;
|
||||
writefln(i.sizeof) ; // print 4
|
||||
int[13] ints1 ; // static integer array of length 13
|
||||
writefln(ints1.sizeof) ; // print 52
|
||||
int[] ints2 = new int[13] ; // dynamic integer array, variable length, currently 13
|
||||
writefln(ints2.sizeof) ; // print 8, all dynamic array has this size
|
||||
writefln(ints2.length) ; // print 13, length is the number of allocated element in aggregated type
|
||||
1
Task/Variable-size-Get/Delphi/variable-size-get.delphi
Normal file
1
Task/Variable-size-Get/Delphi/variable-size-get.delphi
Normal file
|
|
@ -0,0 +1 @@
|
|||
i := sizeof([any variable or structure]);
|
||||
14
Task/Variable-size-Get/Fortran/variable-size-get.f
Normal file
14
Task/Variable-size-Get/Fortran/variable-size-get.f
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
INTEGER, PARAMETER :: i8 = SELECTED_INT_KIND(2)
|
||||
INTEGER, PARAMETER :: i16 = SELECTED_INT_KIND(4)
|
||||
INTEGER, PARAMETER :: i32 = SELECTED_INT_KIND(8)
|
||||
INTEGER, PARAMETER :: i64 = SELECTED_INT_KIND(16)
|
||||
INTEGER(i8) :: onebyte = 0
|
||||
INTEGER(i16) :: twobytes = 0
|
||||
INTEGER(i32) :: fourbytes = 0
|
||||
INTEGER(i64) :: eightbytes = 0
|
||||
|
||||
WRITE (*,*) BIT_SIZE(onebyte), DIGITS(onebyte) ! prints 8 and 7
|
||||
WRITE (*,*) BIT_SIZE(twobytes), DIGITS(twobytes) ! prints 16 and 15
|
||||
WRITE (*,*) BIT_SIZE(fourbytes), DIGITS(fourbytes) ! prints 32 and 31
|
||||
WRITE (*,*) BIT_SIZE(eightbytes), DIGITS(eightbytes) ! prints 64 and 63
|
||||
WRITE (*,*) DIGITS(0.0), DIGITS(0d0) ! prints 24 and 53
|
||||
3
Task/Variable-size-Get/Go/variable-size-get.go
Normal file
3
Task/Variable-size-Get/Go/variable-size-get.go
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import "unsafe"
|
||||
|
||||
unsafe.Sizeof(x)
|
||||
6
Task/Variable-size-Get/Haskell/variable-size-get.hs
Normal file
6
Task/Variable-size-Get/Haskell/variable-size-get.hs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import Foreign
|
||||
|
||||
sizeOf (undefined :: Int) -- size of Int in bytes (4 on mine)
|
||||
sizeOf (undefined :: Double) -- size of Double in bytes (8 on mine)
|
||||
sizeOf (undefined :: Bool) -- size of Bool in bytes (4 on mine)
|
||||
sizeOf (undefined :: Ptr a) -- size of Ptr in bytes (4 on mine)
|
||||
4
Task/Variable-size-Get/IDL/variable-size-get.idl
Normal file
4
Task/Variable-size-Get/IDL/variable-size-get.idl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
arr = intarr(3,4)
|
||||
print,size(arr)
|
||||
;=> prints this:
|
||||
2 3 4 2 12
|
||||
29
Task/Variable-size-Get/Icon/variable-size-get.icon
Normal file
29
Task/Variable-size-Get/Icon/variable-size-get.icon
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
record rec0()
|
||||
record rec4(a,b,c,d)
|
||||
|
||||
procedure main() # get size
|
||||
|
||||
every i := seq(1) do {
|
||||
a0 := &allocated
|
||||
x := case i of {
|
||||
1 : "ABCDEFGH"
|
||||
2 : reverse(x)
|
||||
10 : &digits
|
||||
11 : x--x
|
||||
20 : []
|
||||
21 : [1,2]
|
||||
22 : [1,2,3]
|
||||
30 : set()
|
||||
31 : set("X")
|
||||
32 : set("A","B")
|
||||
40 : table(1)
|
||||
50 : rec0()
|
||||
51 : rec4()
|
||||
60 : create seq(1)
|
||||
99 : break
|
||||
default : next
|
||||
}
|
||||
a1 := &allocated
|
||||
write("type=",type(x)," *x=",*x," bytes allocated=",a1-a0)
|
||||
}
|
||||
end
|
||||
2
Task/Variable-size-Get/J/variable-size-get-1.j
Normal file
2
Task/Variable-size-Get/J/variable-size-get-1.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
some_variable =: 42
|
||||
7!:5<'some_variable'
|
||||
2
Task/Variable-size-Get/J/variable-size-get-2.j
Normal file
2
Task/Variable-size-Get/J/variable-size-get-2.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
some_function =: +/ % #
|
||||
7!:5<'some_function'
|
||||
8
Task/Variable-size-Get/Julia/variable-size-get.julia
Normal file
8
Task/Variable-size-Get/Julia/variable-size-get.julia
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
julia> sizeof(Int8)
|
||||
1
|
||||
|
||||
julia> t = 1
|
||||
1
|
||||
|
||||
julia> sizeof(t)
|
||||
4
|
||||
|
|
@ -0,0 +1 @@
|
|||
ByteCount["somerandomstring"]
|
||||
9
Task/Variable-size-Get/Modula-3/variable-size-get.mod3
Normal file
9
Task/Variable-size-Get/Modula-3/variable-size-get.mod3
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
MODULE Size EXPORTS Main;
|
||||
|
||||
FROM IO IMPORT Put;
|
||||
FROM Fmt IMPORT Int;
|
||||
|
||||
BEGIN
|
||||
Put("Integer in bits: " & Int(BITSIZE(INTEGER)) & "\n");
|
||||
Put("Integer in bytes: " & Int(BYTESIZE(INTEGER)) & "\n");
|
||||
END Size.
|
||||
25
Task/Variable-size-Get/OCaml/variable-size-get-1.ocaml
Normal file
25
Task/Variable-size-Get/OCaml/variable-size-get-1.ocaml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
(** The result is the size given in word.
|
||||
The word size in octet can be found with (Sys.word_size / 8).
|
||||
(The size of all the datas in OCaml is at least one word, even chars and bools.)
|
||||
*)
|
||||
let sizeof v =
|
||||
let rec rec_size d r =
|
||||
if List.memq r d then (1, d) else
|
||||
if not(Obj.is_block r) then (1, r::d) else
|
||||
if (Obj.tag r) = (Obj.double_tag) then (2, r::d) else
|
||||
if (Obj.tag r) = (Obj.string_tag) then (Obj.size r, r::d) else
|
||||
if (Obj.tag r) = (Obj.object_tag) ||
|
||||
(Obj.tag r) = (Obj.closure_tag)
|
||||
then invalid_arg "please only provide datas"
|
||||
else
|
||||
let len = Obj.size r in
|
||||
let rec aux d sum i =
|
||||
if i >= len then (sum, r::d) else
|
||||
let this = Obj.field r i in
|
||||
let this_size, d = rec_size d this in
|
||||
aux d (sum + this_size) (i+1)
|
||||
in
|
||||
aux d (1) 0
|
||||
in
|
||||
fst(rec_size [] (Obj.repr v))
|
||||
;;
|
||||
85
Task/Variable-size-Get/OCaml/variable-size-get-2.ocaml
Normal file
85
Task/Variable-size-Get/OCaml/variable-size-get-2.ocaml
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
# sizeof 234 ;;
|
||||
- : int = 1
|
||||
|
||||
# sizeof 23.4 ;;
|
||||
- : int = 2
|
||||
|
||||
# sizeof (1,2);;
|
||||
- : int = 3
|
||||
|
||||
# sizeof (2, 3.4) ;;
|
||||
- : int = 4
|
||||
|
||||
# sizeof (1,2,3,4,5) ;;
|
||||
- : int = 6
|
||||
|
||||
# sizeof [| 1;2;3;4;5 |] ;;
|
||||
- : int = 6
|
||||
|
||||
# sizeof [1;2;3;4;5] ;;
|
||||
- : int = 11
|
||||
|
||||
(* because a list is equivalent to *)
|
||||
|
||||
# sizeof (1,(2,(3,(4,(5,0))))) ;;
|
||||
- : int = 11
|
||||
|
||||
# type foo = A | B of int | C of int * int ;;
|
||||
type foo = A | B of int | C of int * int
|
||||
|
||||
# sizeof A ;;
|
||||
- : int = 1
|
||||
|
||||
# sizeof (B 3) ;;
|
||||
- : int = 2
|
||||
|
||||
# sizeof (C(1,2)) ;;
|
||||
- : int = 3
|
||||
|
||||
# sizeof true ;;
|
||||
- : int = 1
|
||||
|
||||
# sizeof 'A' ;;
|
||||
- : int = 1
|
||||
|
||||
# sizeof `some_pvar ;;
|
||||
- : int = 1
|
||||
|
||||
# sizeof "" ;;
|
||||
- : int = 1
|
||||
|
||||
# sizeof "Hello!" ;;
|
||||
- : int = 2
|
||||
(* remember the size is given in words
|
||||
(so 4 octets on 32 bits machines) *)
|
||||
|
||||
# for i=0 to 16 do
|
||||
Printf.printf "%d -> %d\n" i (sizeof(String.create i))
|
||||
done;;
|
||||
0 -> 1
|
||||
1 -> 1
|
||||
2 -> 1
|
||||
3 -> 1
|
||||
4 -> 2
|
||||
5 -> 2
|
||||
6 -> 2
|
||||
7 -> 2
|
||||
8 -> 3
|
||||
9 -> 3
|
||||
10 -> 3
|
||||
11 -> 3
|
||||
12 -> 4
|
||||
13 -> 4
|
||||
14 -> 4
|
||||
15 -> 4
|
||||
16 -> 5
|
||||
- : unit = ()
|
||||
|
||||
# sizeof(Array.create 10 0) ;;
|
||||
- : int = 11
|
||||
|
||||
# sizeof(Array.create 10 (String.create 20)) ;;
|
||||
- : int = 16
|
||||
|
||||
# sizeof(Array.init 10 (fun _ -> String.create 20)) ;;
|
||||
- : int = 61
|
||||
1
Task/Variable-size-Get/PARI-GP/variable-size-get-1.pari
Normal file
1
Task/Variable-size-Get/PARI-GP/variable-size-get-1.pari
Normal file
|
|
@ -0,0 +1 @@
|
|||
sizebyte(x)
|
||||
1
Task/Variable-size-Get/PARI-GP/variable-size-get-2.pari
Normal file
1
Task/Variable-size-Get/PARI-GP/variable-size-get-2.pari
Normal file
|
|
@ -0,0 +1 @@
|
|||
lg(x)
|
||||
8
Task/Variable-size-Get/PL-I/variable-size-get.pli
Normal file
8
Task/Variable-size-Get/PL-I/variable-size-get.pli
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
put skip list (SIZE(x)); /* gives the number of bytes occupied by X */
|
||||
/* whatever data type or structure it is. */
|
||||
|
||||
put skip list (CURRENTSIZE(x));
|
||||
/* gives the current number of bytes of X */
|
||||
/* actually used by such things as a */
|
||||
/* varying-length string, including its */
|
||||
/* length field. */
|
||||
1
Task/Variable-size-Get/Pascal/variable-size-get.pascal
Normal file
1
Task/Variable-size-Get/Pascal/variable-size-get.pascal
Normal file
|
|
@ -0,0 +1 @@
|
|||
i := sizeof([any variable or structure]);
|
||||
6
Task/Variable-size-Get/Perl/variable-size-get.pl
Normal file
6
Task/Variable-size-Get/Perl/variable-size-get.pl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
use Devel::Size;
|
||||
|
||||
my $var = 9384752;
|
||||
my @arr = (1, 2, 3, 4, 5, 6);
|
||||
print size($var);
|
||||
print total_size(@arr);
|
||||
10
Task/Variable-size-Get/Pop11/variable-size-get.pop11
Normal file
10
Task/Variable-size-Get/Pop11/variable-size-get.pop11
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
;;; Prints 0 because small integers need no heap storage
|
||||
datasize(12) =>
|
||||
;;; Prints 3: 3 character fits into single machine word, 1 word
|
||||
;;; for tag, 1 for length
|
||||
datasize('str') =>
|
||||
;;; 3 element vector takes 5 words: 3 for values, 1 for tag, 1 for
|
||||
;;; length
|
||||
datasize({1 2 3}) =>
|
||||
;;; Prints 3 because only first node counts
|
||||
datasize([1 2 3]) =>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Define a
|
||||
Debug SizeOf(a)
|
||||
; This also works for structured variables
|
||||
15
Task/Variable-size-Get/Python/variable-size-get-1.py
Normal file
15
Task/Variable-size-Get/Python/variable-size-get-1.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
>>> from array import array
|
||||
>>> argslist = [('l', []), ('c', 'hello world'), ('u', u'hello \u2641'),
|
||||
('l', [1, 2, 3, 4, 5]), ('d', [1.0, 2.0, 3.14])]
|
||||
>>> for typecode, initializer in argslist:
|
||||
a = array(typecode, initializer)
|
||||
print a, '\tSize =', a.buffer_info()[1] * a.itemsize
|
||||
del a
|
||||
|
||||
|
||||
array('l') Size = 0
|
||||
array('c', 'hello world') Size = 11
|
||||
array('u', u'hello \u2641') Size = 14
|
||||
array('l', [1, 2, 3, 4, 5]) Size = 20
|
||||
array('d', [1.0, 2.0, 3.1400000000000001]) Size = 24
|
||||
>>>
|
||||
2
Task/Variable-size-Get/Python/variable-size-get-2.py
Normal file
2
Task/Variable-size-Get/Python/variable-size-get-2.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import sys
|
||||
sys.getsizeof(obj)
|
||||
14
Task/Variable-size-Get/R/variable-size-get.r
Normal file
14
Task/Variable-size-Get/R/variable-size-get.r
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Results are system dependent
|
||||
num <- c(1, 3, 6, 10)
|
||||
object.size(num) # e.g. 56 bytes
|
||||
|
||||
#Allocating vectors using ':' results in less memory being (reportedly) used
|
||||
num2 <- 1:4
|
||||
object.size(num2) # e.g. 40 bytes
|
||||
|
||||
#Memory shared by objects isn't always counted
|
||||
l <- list(a=c(1, 3, 6, 10), b=1:4)
|
||||
object.size(l) # e.g. 280 bytes
|
||||
|
||||
l2 <- list(num, num2)
|
||||
object.size(l2) # e.g. 128 bytes
|
||||
60
Task/Variable-size-Get/REXX/variable-size-get.rexx
Normal file
60
Task/Variable-size-Get/REXX/variable-size-get.rexx
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*REXX program demonstrates (see the penultimate statment) how to */
|
||||
/* to find the size (length) of the value of a REXX variable. */
|
||||
|
||||
/*REXX doesn't reserve any storage for any variables, as all variables */
|
||||
/*are stored as character strings, including boolean. Storage is */
|
||||
/*obtained as necessary when REXX variables are assigned (or reassigned)*/
|
||||
|
||||
a = 456 /*length of A is 3 */
|
||||
b = "heptathlon" /*length of B is 10 */
|
||||
c = "heptathlon (7 events)" /*length of C is 21 */
|
||||
d = '' /*length of D is 0 */
|
||||
d = "" /*same as above. */
|
||||
d = left('space junk' ,0) /*same as above. */
|
||||
d = /*same as above. */
|
||||
e = 99-9 /*length of E is 2 (e=90) */
|
||||
f = copies(a,100) /*length of F is 300 (a=456)*/
|
||||
g.1 = -1 /*length of G.1 is 2 */
|
||||
g.2 = -1.0000 /*length of G.2 is 7 */
|
||||
/*length of HHH is 3 */
|
||||
|
||||
/*Note that when a REXX variable */
|
||||
/*isn't SET, then the value of it*/
|
||||
/*is the uppercased name itself, */
|
||||
/*so in this case (upper): HHH */
|
||||
|
||||
something = copies(a, random(100)) /*length is something, all right,*/
|
||||
/*could be 3 to 300 bytes, by gum*/
|
||||
thingLen = length(something) /*use LENGTH bif to find its len.*/
|
||||
say 'length of SOMETHING =' thingLen /*display the length of SOMETHING*/
|
||||
|
||||
/*┌────────────────────────────────────────────────────────────────────┐
|
||||
│ Note that the variable's data (value) isn't the true cost of the │
|
||||
│ size of the variable's value. REXX also keeps the name of │
|
||||
│ the (fully qualified) variable as well. │
|
||||
│ │
|
||||
│ Most REXX interpreters keep (at a miminum): │
|
||||
│ │
|
||||
│ ∙ a four-byte field which contains the length of the value │
|
||||
│ ∙ a four-byte field which contains the length of the var name │
|
||||
│ ∙ an N-byte field which contains the name of the variable │
|
||||
│ ∙ an X-byte field which contains the variable's value │
|
||||
│ ∙ a one-byte field which contains the status of the variable │
|
||||
│ │
|
||||
│ [Note that PC/REXX uses a two-byte field for the first two fields] │
|
||||
│ │
|
||||
│ │
|
||||
│ Consider the following two DO loops assigning a million variables: │
|
||||
│ │
|
||||
│ do j=1 to 1000000 │
|
||||
│ integer_numbers.j=j │
|
||||
│ end │
|
||||
│ ════════ and ════════ │
|
||||
│ do k=1 to 1000000 │
|
||||
│ #.k=k │
|
||||
│ end │
|
||||
│ │
|
||||
│ The "j" loop uses 35,777,792 bytes for the compound variables, │
|
||||
│ The "k" loop uses 21,777,792 bytes for the compound variables, │
|
||||
│ (excluding the DO loop indices [j and k] themselves). │
|
||||
└────────────────────────────────────────────────────────────────────┘*/
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
$$ MODE TUSCRIPT,{}
|
||||
string="somerandomstring"
|
||||
size=SIZE(string)
|
||||
length=LENGTH(string)
|
||||
|
||||
PRINT "string: ",string
|
||||
PRINT "has size: ",size
|
||||
PRINT "and length: ",length
|
||||
1
Task/Variable-size-Get/Tcl/variable-size-get.tcl
Normal file
1
Task/Variable-size-Get/Tcl/variable-size-get.tcl
Normal file
|
|
@ -0,0 +1 @@
|
|||
string bytelength $var
|
||||
2
Task/Variable-size-Get/Toka/variable-size-get-1.toka
Normal file
2
Task/Variable-size-Get/Toka/variable-size-get-1.toka
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
char-size .
|
||||
cell-size .
|
||||
2
Task/Variable-size-Get/Toka/variable-size-get-2.toka
Normal file
2
Task/Variable-size-Get/Toka/variable-size-get-2.toka
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
needs floats
|
||||
float-size .
|
||||
5
Task/Variable-size-Get/UNIX-Shell/variable-size-get.sh
Normal file
5
Task/Variable-size-Get/UNIX-Shell/variable-size-get.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# In the shell all variables are stored as strings, so we use the same technique
|
||||
# as for finding the length of a string:
|
||||
greeting='Hello, world!'
|
||||
greetinglength=`printf '%s' "$greeting" | wc -c`
|
||||
echo "The greeting is $greetinglength characters in length"
|
||||
5
Task/Variable-size-Get/Ursala/variable-size-get.ursala
Normal file
5
Task/Variable-size-Get/Ursala/variable-size-get.ursala
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#import std
|
||||
|
||||
#cast %nL
|
||||
|
||||
examples = <weight 'hello',mpfr..prec 1.0E+0>
|
||||
5
Task/Variable-size-Get/Vala/variable-size-get.vala
Normal file
5
Task/Variable-size-Get/Vala/variable-size-get.vala
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
void main(){
|
||||
ulong x = sizeof(int); // returns # of bytes used to store an int
|
||||
// is returned as a ulong, but could be typecasted to int with: int x = (int) sizeof(int)
|
||||
stdout.printf("%lu\n", x);
|
||||
}
|
||||
9
Task/Variable-size-Get/XPL0/variable-size-get.xpl0
Normal file
9
Task/Variable-size-Get/XPL0/variable-size-get.xpl0
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
include c:\cxpl\codes;
|
||||
int Size;
|
||||
int A, B;
|
||||
real X, Y;
|
||||
[Size:= addr B - addr A;
|
||||
IntOut(0, Size); CrLf(0);
|
||||
Size:= addr Y - addr X;
|
||||
IntOut(0, Size); CrLf(0);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue