Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
from: http://rosettacode.org/wiki/Variable_size/Get
note: Type System

View file

@ -0,0 +1,4 @@
Demonstrate how to get the size of a variable.
See also: [[Host introspection]]

View file

@ -0,0 +1,3 @@
Int64 i
print(T(i).size)
print(Int64.size)

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

View file

@ -0,0 +1,32 @@
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.sampler.getSize;
public class VariableSizeGet extends Sprite {
public function VariableSizeGet() {
if ( stage ) _init();
else addEventListener(Event.ADDED_TO_STAGE, _init);
}
private function _init(e:Event = null):void {
var i:int = 1;
var n:Number = 0.5;
var s:String = "abc";
var b:Boolean = true;
var date:Date = new Date();
trace("An int contains " + getSize(i) + " bytes."); // 4
trace("A Number contains " + getSize(n) + " bytes."); // 8
trace("The string 'abc' contains " + getSize(s) + " bytes."); // 24
trace("A Boolean contains " + getSize(b) + " bytes."); // 4
trace("A Date object contains " + getSize(date) + " bytes."); // 48
}
}
}

View 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

View file

@ -0,0 +1,25 @@
100 PRINT "SIZE OF INTEGER I% IS ";:I% = I%: GOSUB 240
110 PRINT "SIZE OF FLOAT I IS ";:I = I: GOSUB 240
120 PRINT "SIZE OF STRING I$ IS ";:I$ = I$: GOSUB 240
130 PRINT " LEN OF STRING I$ IS " LEN (I$)
140 PRINT "SIZE OF FLOAT ARG N IS ";: DEF FN I(N) = 0: GOSUB 240
150 PRINT "SIZE OF FUNCTION FN I IS ";: PRINT MID$ ( STR$ ( FN I(0)),1,0);: GOSUB 240
160 PRINT "ARRAYS:"
170 PRINT "SIZE OF FLOAT I(1) IS ";:I(1) = I(1): GOSUB 240
180 PRINT "SIZE OF INTEGER I%(2) IS ";:I%(2) = I%(2): GOSUB 240
190 PRINT "SIZE OF STRING I$(3) IS ";:I$(3) = I$(3): GOSUB 240
200 PRINT " LEN OF STRING I$(3) IS " LEN (I$(3))
210 PRINT "SIZE OF STRING I$(4) IS ";:I$(4) = "HELLO, WORLD!": GOSUB 240
220 PRINT " LEN OF STRING I$(4) IS " LEN (I$(4))
230 END
240 GOSUB 250: PRINT PEEK (236) + PEEK (237) * 256: RETURN
250 POKE 236,12: POKE 237,0: IF PEEK (129) > 127 AND PEEK (130) < 128 THEN RETURN
260 POKE 236,5
270 IF PEEK (129) < 128 AND PEEK (130) > 127 GOTO 310STR
280 IF PEEK (131) + PEEK (132) * 256 < PEEK (107) + PEEK (108) * 256 THEN RETURN
290 IF PEEK (129) < 128 AND PEEK (130) < 128 THEN RETURN
300 POKE 236,2: IF PEEK (129) > 127 AND PEEK (130) > 127 THEN RETURN
310 IF PEEK (131) + PEEK (132) * 256 > = PEEK (107) + PEEK (108) * 256 THEN POKE 236,3
320 IF PEEK ( PEEK (131) + PEEK (132) * 256) + PEEK (236) > 255 THEN POKE 237,1: POKE 236, PEEK ( PEEK (131) + PEEK (132) * 256) + PEEK (236) - 256: RETURN
330 POKE 236, PEEK ( PEEK (131) + PEEK (132) * 256) + PEEK (236)
340 RETURN

View file

@ -0,0 +1,2 @@
VarSetCapacity(Var, 10240000) ; allocate 10 megabytes
MsgBox % size := VarSetCapacity(Var) ; 10240000

View file

@ -0,0 +1,2 @@
10 REM this only works with strings
20 PRINT LEN(variable$)

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

View file

@ -0,0 +1,12 @@
i = 1 #Integer
f = 1.0 #Float
s$ = "cad" #String
dim a(99) #Array
A = {1, 2, 3} #Anonymous array
m = {"key" -> 1} #Map
print typeof(i) # 1
print typeof(f) # 2
print typeof(s$) # 3
print typeof(A) # 4
print typeof(m) # 6

View 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{})

View file

@ -0,0 +1,11 @@
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 << }

View file

@ -0,0 +1 @@
main : { (1 2 (3 4) 5 6) unload size %d << }

View file

@ -0,0 +1,2 @@
#include <cstdlib>
std::size_t intsize = sizeof(int);

View file

@ -0,0 +1,3 @@
#include <climits>
#include <cstdlib>
std::size_t intbits = CHAR_BITS*sizeof(int);

View file

@ -0,0 +1,3 @@
#include <cstdlib>
int a = 1;
std::size_t a_size = sizeof a;

View file

@ -0,0 +1,2 @@
#include <cstdlib>
std::size_t size = sizeof (3*6 + 7.5);

View file

@ -0,0 +1,9 @@
class Program
{
static void Main(string[] args)
{
int i = sizeof(int);
Console.WriteLine(i);
Console.ReadLine();
}
}

View file

@ -0,0 +1 @@
printf("An int contains %u bytes.\n", sizeof(int));

View file

@ -0,0 +1,61 @@
identification division.
program-id. variable-size-get.
environment division.
configuration section.
repository.
function all intrinsic.
data division.
working-storage section.
01 bc-len constant as length of binary-char.
01 fd-34-len constant as length of float-decimal-34.
77 fixed-character pic x(13).
77 fixed-national pic n(13).
77 fixed-nine pic s9(5).
77 fixed-separate pic s9(5) sign trailing separate.
77 computable-field pic s9(5) usage computational-5.
77 formatted-field pic +z(4),9.
77 binary-field usage binary-double.
01 pointer-item usage pointer.
01 group-item.
05 first-inner pic x occurs 0 to 3 times depending on odo.
05 second-inner pic x occurs 0 to 5 times depending on odo-2.
01 odo usage index value 2.
01 odo-2 usage index value 4.
procedure division.
sample-main.
display "Size of:"
display "BINARY-CHAR : " bc-len
display " bc-len constant : " byte-length(bc-len)
display "FLOAT-DECIMAL-34 : " fd-34-len
display " fd-34-len constant : " byte-length(fd-34-len)
display "PIC X(13) field : " length of fixed-character
display "PIC N(13) field : " length of fixed-national
display "PIC S9(5) field : " length of fixed-nine
display "PIC S9(5) sign separate : " length of fixed-separate
display "PIC S9(5) COMP-5 : " length of computable-field
display "ALPHANUMERIC-EDITED : " length(formatted-field)
display "BINARY-DOUBLE field : " byte-length(binary-field)
display "POINTER field : " length(pointer-item)
>>IF P64 IS SET
display " sizeof(char *) > 4"
>>ELSE
display " sizeof(char *) = 4"
>>END-IF
display "Complex ODO at 2 and 4 : " length of group-item
set odo down by 1.
set odo-2 up by 1.
display "Complex ODO at 1 and 5 : " length(group-item)
goback.
end program variable-size-get.

View file

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

View file

@ -0,0 +1 @@
(12 48 24)

View file

@ -0,0 +1,7 @@
(let (items)
(gc) ; name varies by implementation
(room)
(dotimes (x 512)
(push (allocate-something-of-interest) items))
(gc)
(room))

View 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

View file

@ -0,0 +1 @@
i := sizeof({any variable or data type identifier});

View file

@ -0,0 +1,22 @@
list = [1,2,3]
IO.puts length(list) #=> 3
tuple = {1,2,3,4}
IO.puts tuple_size(tuple) #=> 4
string = "Elixir"
IO.puts String.length(string) #=> 6
IO.puts byte_size(string) #=> 6
IO.puts bit_size(string) #=> 48
utf8 = "○×△"
IO.puts String.length(utf8) #=> 3
IO.puts byte_size(utf8) #=> 8
IO.puts bit_size(utf8) #=> 64
bitstring = <<3 :: 2>>
IO.puts byte_size(bitstring) #=> 1
IO.puts bit_size(bitstring) #=> 2
map = Map.new([{:b, 1}, {:a, 2}])
IO.puts map_size(map) #=> 2

View file

@ -0,0 +1,11 @@
USING: layouts memory prettyprint ;
! Show size in bytes
{ 1 2 3 } size . ! 48
1231298302914891021239102 size . ! 48
! Doesn't work on fixnums and other immediate objects
10 size . ! 0
! Show number of bits in a fixnum
fixnum-bits . ! 60

View file

@ -0,0 +1,2 @@
: .CELLSIZE ( -- ) CR 1 CELLS . ." Bytes" ;
VARIABLE X ( creates a variable 1 cell wide)

View file

@ -0,0 +1,4 @@
.CELLSIZE
4 Bytes ok
-1 X ! ok
HEX X @ U. FFFFFFFF ok

View 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

View file

@ -0,0 +1,20 @@
' FB 1.05.0 Win64
Dim i As Integer
Dim l As Long
Dim s As Short
Dim b As Byte
Print "An integer occupies "; SizeOf(i); " bytes"
Print "A long occupies "; SizeOf(l); " bytes"
Print "A short occupies "; SizeOf(s); " bytes"
Print "A byte occupies "; SizeOf(b); " byte"
' or use type directly rather than a variable
Print "A boolean occupies "; SizeOf(Boolean); " byte"
Print "A single occupies "; SizeOf(Single); " bytes"
Print "A double occupies "; SizeOf(Double); " bytes"
Print
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,9 @@
include "NSLog.incl"
void local fn Doit
NSLog(@"%ld",sizeof(long))
end fn
fn DoIt
HandleEvents

View file

@ -0,0 +1,16 @@
Public Sub Main()
Print "Boolean =\t " & SizeOf(gb.Boolean)
Print "Byte =\t\t " & SizeOf(gb.Byte)
Print "Short =\t\t " & SizeOf(gb.Short)
Print "Integer =\t " & SizeOf(gb.Integer)
Print "Single =\t " & SizeOf(gb.Single)
Print "Long =\t\t " & SizeOf(gb.Long)
Print "Float =\t\t " & SizeOf(gb.Float)
Print "Date =\t\t " & SizeOf(gb.Date)
Print "String =\t " & SizeOf(gb.String)
Print "Object =\t " & SizeOf(gb.Object)
Print "Pointer =\t " & SizeOf(gb.Pointer)
Print "Variant =\t " & SizeOf(gb.Variant)
End

View file

@ -0,0 +1,3 @@
import "unsafe"
unsafe.Sizeof(x)

View file

@ -0,0 +1,25 @@
package main
import (
"fmt"
"reflect"
"runtime"
"unsafe"
)
func main() {
// unsafe.Sizeof returns the size in bytes.
var i int
fmt.Println(unsafe.Sizeof(i))
// The size returned is that of the top level object and does not
// include any referenced data. A type like string always returns
// the same number, the size of the string header.
fmt.Println(unsafe.Sizeof("Rosetta"))
fmt.Println(unsafe.Sizeof("Code"))
// For some untrusted environments, package unsafe is not available
// but reflect is. The Size method of a type will return the same value
// as unsafe.Sizeof.
fmt.Println(reflect.TypeOf("Cod").Size())
// Some sizes are implementation dependent.
fmt.Println(runtime.Version(), runtime.GOARCH)
}

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

View file

@ -0,0 +1,4 @@
arr = intarr(3,4)
print,size(arr)
;=> prints this:
2 3 4 2 12

View 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

View file

@ -0,0 +1,2 @@
some_variable =: 42
7!:5<'some_variable'

View file

@ -0,0 +1,2 @@
some_function =: +/ % #
7!:5<'some_function'

View file

@ -0,0 +1,13 @@
public final class VariableSize {
public static void main(String[] aArgs) {
System.out.println("A Byte variable occupies: " + Byte.SIZE / 8 + " byte");
System.out.println("A Char variable occupies: " + Character.SIZE / 8 + " bytes");
System.out.println("A Short variable occupies: " + Short.SIZE / 8 + " bytes");
System.out.println("A Float variable occupies: " + Float.SIZE / 8 + " bytes");
System.out.println("An Integer variable occupies: " + Integer.SIZE / 8 + " bytes");
System.out.println("A Double variable occupies: " + Double.SIZE / 8 + " bytes");
System.out.println("A Long variable occupies: " + Long.SIZE / 8 + " bytes");
}
}

View file

@ -0,0 +1,8 @@
julia> sizeof(Int8)
1
julia> t = 1
1
julia> sizeof(t)
8

View file

@ -0,0 +1,12 @@
// version 1.1.2
fun main(args: Array<String>) {
/* sizes for variables of the primitive types (except Boolean which is JVM dependent) */
println("A Byte variable occupies: ${java.lang.Byte.SIZE / 8} byte")
println("A Short variable occupies: ${java.lang.Short.SIZE / 8} bytes")
println("An Int variable occupies: ${java.lang.Integer.SIZE / 8} bytes")
println("A Long variable occupies: ${java.lang.Long.SIZE / 8} bytes")
println("A Float variable occupies: ${java.lang.Float.SIZE / 8} bytes")
println("A Double variable occupies: ${java.lang.Double.SIZE / 8} bytes")
println("A Char variable occupies: ${java.lang.Character.SIZE / 8} bytes")
}

View file

@ -0,0 +1,22 @@
local(
mystring = 'Hello World',
myarray = array('one', 'two', 3),
myinteger = 1234
)
// size of a string will be a character count
#mystring -> size
'<br />'
// size of an array or map will be a count of elements
#myarray -> size
'<br />'
// elements within an array can report size
#myarray -> get(2) -> size
'<br />'
// integers or decimals does not have sizes
//#myinteger -> size // will fail
// an integer can however be converted to a string first
string(#myinteger) -> size

View file

@ -0,0 +1,6 @@
> s = "hello"
> print(#s)
5
> t = { 1,2,3,4,5 }
> print(#t)
5

View file

@ -0,0 +1 @@
ByteCount["somerandomstring"]

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

View file

@ -0,0 +1 @@
10 PRINT LEN(VARIABLE$)

View file

@ -0,0 +1 @@
echo "An int contains ", sizeof(int), " bytes."

View 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))
;;

View 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

View file

@ -0,0 +1,7 @@
package main
import "core:fmt"
main :: proc() {
fmt.println("An int contains", size_of(int), "bytes.")
}

View file

@ -0,0 +1 @@
sizebyte(x)

View file

@ -0,0 +1 @@
lg(x)

View 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. */

View file

@ -0,0 +1,6 @@
use Devel::Size qw(size total_size);
my $var = 9384752;
my @arr = (1, 2, 3, 4, 5, 6);
print size($var); # 24
print total_size(\@arr); # 256

View file

@ -0,0 +1,3 @@
(phixonline)-->
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"An integer contains %d bytes.\n"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">machine_word</span><span style="color: #0000FF;">())</span>
<!--

View 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]) =>

View file

@ -0,0 +1,3 @@
Define a
Debug SizeOf(a)
; This also works for structured variables

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

View file

@ -0,0 +1,2 @@
import sys
sys.getsizeof(obj)

View 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

View file

@ -0,0 +1,60 @@
/*REXX program demonstrates (see the penultimate statement) 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).
*/

View file

@ -0,0 +1,5 @@
#lang racket
(require ffi/unsafe)
(define-syntax-rule (sizes t ...)
(begin (printf "sizeof(~a) = ~a\n" 't (ctype-sizeof t)) ...))
(sizes _byte _short _int _long _llong _float _double)

View file

@ -0,0 +1,12 @@
# Textual strings are measured in characters (graphemes)
my $string = "abc";
# Arrays are measured in elements.
say $string.chars; # 3
my @array = 1..5;
say @array.elems; # 5
# Buffers may be viewed either as a byte-string or as an array of elements.
my $buffer = '#56997; means "four dragons".'.encode('utf8');
say $buffer.bytes; # 26
say $buffer.elems; # 26

View file

@ -0,0 +1,11 @@
list1 = list(2)
list2 = list(4)
list3 = list(6)
list4 = list(7)
list5 = list(5)
see "Size of list1 is : " + len(list1) + nl
see "Size of list2 is : " + len(list2) + nl
see "Size of list3 is : " + len(list3) + nl
see "Size of list4 is : " + len(list4) + nl
see "Size of list5 is : " + len(list5) + nl

View file

@ -0,0 +1,5 @@
require 'objspace'
p ObjectSpace.memsize_of("a"*23) #=> 0
p ObjectSpace.memsize_of("a"*24) #=> 25
p ObjectSpace.memsize_of("a"*1000) #=> 1001

View file

@ -0,0 +1,10 @@
use std::mem;
fn main() {
// Specify type
assert_eq!(4, mem::size_of::<i32>());
// Provide a value
let arr: [u16; 3] = [1, 2, 3];
assert_eq!(6, mem::size_of_val(&arr));
}

View file

@ -0,0 +1,9 @@
def nBytes(x: Double) = ((Math.log(x) / Math.log(2) + 1e-10).round + 1) / 8
val primitives: List[(Any, Long)] =
List((Byte, Byte.MaxValue),
(Short, Short.MaxValue),
(Int, Int.MaxValue),
(Long, Long.MaxValue))
primitives.foreach(t => println(f"A Scala ${t._1.toString.drop(13)}%-5s has ${nBytes(t._2)} bytes"))

View file

@ -0,0 +1 @@
sizeofValue(x)

View file

@ -0,0 +1,9 @@
// sizeof and sizeofValue return the size in bytes.
println(sizeof(Int))
var i: Int = 42
println(sizeofValue(i))
// The size returned is that of the top level value and does not
// include any referenced data. A type like String always returns
// the same number, the size of the String struct.
println(sizeofValue("Rosetta"))
println(sizeofValue("Code"))}

View file

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

View file

@ -0,0 +1,5 @@
struct foo {
uint32_t x : 17;
uint8_t y : 3;
char z[16];
};

View file

@ -0,0 +1 @@
string bytelength $var

View file

@ -0,0 +1,2 @@
char-size .
cell-size .

View file

@ -0,0 +1,2 @@
needs floats
float-size .

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

View file

@ -0,0 +1,5 @@
#import std
#cast %nL
examples = <weight 'hello',mpfr..prec 1.0E+0>

View file

@ -0,0 +1 @@
sizeof(i64)

View file

@ -0,0 +1,6 @@
void main(){
/* you can replace the int below with any of the vala supported datatypes
see the vala documentation for valid datatypes.
*/
print(@"$(sizeof(int))\n");
}

View 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);
]

View file

@ -0,0 +1,13 @@
print frnfn_size("uint8") //1
print frnfn_size("int8") //1
print frnfn_size("uint16") //2
print frnfn_size("int16") //2
print frnfn_size("uint32") //4
print frnfn_size("int32") //4
print frnfn_size("uint64") //8
print frnfn_size("int64") //8
print frnfn_size("float") //4
print frnfn_size("double") //8
print frnfn_size("char") //1
print frnfn_size("int") //4
print frnfn_size("short") //2

View file

@ -0,0 +1,8 @@
(123).len() //-->1 (byte)
(0).MAX.len() //-->8 (bytes), ie the max number of bytes in an int
(1.0).MAX.len() //-->8 (bytes), ie the max number of bytes in an float
"this is a test".len() //-->14
L(1,2,3,4).len() //-->4
Dictionary("1",1, "2",2).len() //-->2 (keys)
Data(0,Int,1,2,3,4).len() //-->4 (bytes)
Data(0,String,"1","2","3","4").len() //-->8 bytes (ASCIIZ)