Programación General > Pascal

 punteros

<< < (2/2)

Enko:

--- Citar ---he GetMem procedure attempts to get the specified StorageSize bytes of storage, storing a pointer to the storage in StoragePointer.
 
If the allocation fails, then a EOutOfMemory exception is raised.
 
The storage is not initialised in any way.
--- Fin de la cita ---
Por lo visto en Delphi lanza una excepcion tambien en vez de devolver nil.

aguila3000:
Y que sería mejor ¿Qué devuelve nil? o ¿Usar excepciones?

aguila3000:
Haciendo preguntas por qui y por alla, encontre esto:
  http://www.freepascal.org/docs-html/prog/progsu158.html
y esto:
  http://www.freepascal.org/docs-html/rtl ... fails.html

en fpc existe una variable ReturnNilIfGrowHeapFails, que define el comportamiento de la administración de memoria, si es true entonces las funciones como getmem, reallocmem y new devuelven nil, en caso contrario devuelve false.
Por defecto es false, No se realmente porque estará en False, si alguien sabe me gustaría saberlo.

El programa quedaría algo así:

--- Código: Pascal ---Var p01,p02,p03,p04:^byte; Begin    ReturnNilIfGrowHeapFails:=true;   getmem(p01,1024*1024*1024);   if (p01<>nil) then Writeln('ok 1')   else Writeln('ko 1');    getmem(p02,1024*1024*1024);   if (p02<>nil) then Writeln('ok 2')   else Writeln('ko 2');     getmem(p03,1024*1024*1024);   if (p03<>nil) then Writeln('ok 3')   else Writeln('ko 3');    getmem(p04,1024*1024*1024);   if (p04<>nil) then Writeln('ok 4')   else Writeln('ko 4'); End.    

Navegación

[0] Índice de Mensajes

[*] Página Anterior

Ir a la versión completa