[TUT] Llaves { } en variables normales y char
#1
Variable char obsoleta:
Se pensaba que las variables char ocupaban 1Byte,pero resulta que son asignadas de a 4Bytes, siendo igual que cualquier otra variable. De todos modos las llaves { } siguen siendo útil.

__________________________________________________________

Espesemos por lo básico:
Byte y bit:
Bit (Binary digit) es la mas mínima cantidad de información, solo se puede representar por 1 o 0 (true/false).
Byte es el conjunto de 8 bits.

Tipos de datos en Pawn
Pawn soporta un solo tipo de dato, el tipo cell(celda).
Cell es del tipo integer, tiene un tamaño de 32 bits (4 Bytes) o 64 bits (8 Bytes) dependiendo del equipo.

AmxModx
AmxModx solo soporta un único tipo de dato para sus natives y forwards, el tipo cell.

Etiquetas
Tal vez alguno se pregunte ¿y los tipos float/bool?.
En pawn Float y bool solo son etiquetas,no es un tipo de dato.


Llaves { }:
Hace un tiempo se pensaba que eran para acceder a cada elemento de una variable char, pero no resulto ser del todo cierto. El verdadero uso es para acceder a cada byte de cualquier variable.
Como solo se puede acceder a un byte, los valores numéricos que se pueden almacenar son de 0 a 255

¿Como utilizar las llaves { }?

Sintaxis básica:
Código PHP:
new test[1]

test{0} = 4
test
{1} = 5
test
{2} = 6
test
{3} = 7

test
{4} = // Invalido

server_print("[%d][%d][%d][%d]"test{0}, test{1}, test{2}, test{3})


/*Valido*/
new test[2]

test{0} = 4
test
{1} = 5
test
{2} = 6
test
{3} = 7
test
{4} = 8
test
{5} = 9
test
{6} = 10 
test
{7} = 11 

Ejemplo en uso
Código PHP:
/*En cualquiera de los dos casos la variable termina ocupando 36 Bytes*/
new g_is_connected[9// o g_is_connected[33 char]


public client_putinserver(id)
{
    
g_is_connected{id} = 1
}

public 
client_disconnect(id)
{
    
g_is_connected{id} = 0
}

public 
una_funcion(id)
{
    if(!
g_is_connected{id})
        
// no esta conectado

Usando llaves nos ahorramos 96 Bytes


¿En que casos es recomendado usar?
Cuando tengas que almacenar mas de un dato y que los valores de esos datos se encuentren entre 0 y 255
Responder


Mensajes en este tema
[TUT] Llaves { } en variables normales y char - por Destro - 27/04/2014, 05:28 AM
RE: Variable tipo char - por roccoxx - 27/04/2014, 11:39 AM
Re: Variable tipo char - por Neeeeeeeeeel.- - 27/04/2014, 12:38 PM
RE: Variable tipo char - por roccoxx - 27/04/2014, 12:57 PM
RE: Variable tipo char - por kirito - 27/04/2014, 12:51 PM
RE: Variable tipo char - por Zonejo - 27/04/2014, 04:06 PM
RE: Variable tipo char - por Destro - 27/04/2014, 05:37 PM
RE: Variable tipo char - por CSAxel - 27/04/2014, 04:43 PM
RE: Variable tipo char - por Zonejo - 27/04/2014, 05:08 PM
RE: Variable tipo char - por [R]ak - 28/04/2014, 12:30 AM
RE: [TUT] Variable tipo char - por Federicomb - 28/04/2014, 12:57 PM
RE: [TUT] Variable tipo char - por mongito100 - 28/04/2014, 01:01 PM
RE: [TUT] Variable tipo char - por Federicomb - 28/04/2014, 01:05 PM
RE: [TUT] Variable tipo char - por mongito100 - 28/04/2014, 01:14 PM
RE: [TUT] Variable tipo char - por Neeeeeeeeeel.- - 30/04/2014, 08:50 AM
RE: [TUT] Variable tipo char - por wicho - 30/04/2014, 02:31 AM
RE: [TUT] Variable tipo char - por Milashkasiya - 30/04/2014, 10:44 AM
RE: [TUT] Variable tipo char - por Destro - 02/06/2014, 04:19 PM
RE: [TUT] Variable tipo char - por Kane - 06/06/2014, 07:53 PM
RE: [TUT] Variable tipo char - por alan_el_more - 20/07/2014, 07:37 PM
RE: [TUT] Variable tipo char - por Destro - 20/07/2014, 08:29 PM
RE: [TUT] Variable tipo char - por alan_el_more - 20/07/2014, 08:31 PM
RE: [TUT] Variable tipo char - por mongito100 - 10/09/2014, 09:16 PM
RE: [TUT] Variable tipo char - por meTaLiCroSS - 11/09/2014, 01:16 AM

Salto de foro:


Usuarios navegando en este tema: 2 invitado(s)