silvarudo 0 Denunciar post Postado Julho 31, 2010 Oi gente, beleza? Seguinte: Estou com um projeto que utiliza calculos muito grandes e demorados, por isso criei um array com valores predefinidos tipo: ArrayValores: Array[0..39800] of Integer = (0, 12, 0, 90, 58, 100...(39800 valores)]; deixou o programa bem mais rápido só que com muita memória. Preciso saber se é possível utilizar o array nos calculos e depois dispor dele liberando memória. Como deletá-lo? Compartilhar este post Link para o post Compartilhar em outros sites
Raficcha 1 Denunciar post Postado Agosto 3, 2010 Se estes arrays são dinamicos, você pode utilizar setLength(vetor, 0); Compartilhar este post Link para o post Compartilhar em outros sites
bdexterholland 0 Denunciar post Postado Agosto 3, 2010 Eu estava olhando o help do delphi para obter maiores informações sobre o o assunto e encontrei o texto abaixo, não sei se será o que procura, eu não realizei nenhum teste mas pode exclarecer algumas coisas Memory Management on the Win32 Platform The following material describes how memory management on Win32 is handled, and briefly describes memory issues of variables. The Memory Manager (Win32 Only) The memory manager manages all dynamic memory allocations and deallocations in an application. The New, Dispose, GetMem, ReallocMem, and FreeMem standard procedures use the memory manager, and all objects and long strings are allocated through the memory manager. The memory manager is optimized for applications that allocate large numbers of small- to medium-sized blocks, as is typical for object-oriented applications and applications that process string data. Other memory managers, such as the implementations of GlobalAlloc, LocalAlloc, and private heap support in Windows, typically do not perform well in such situations, and would slow down an application if they were used directly. To ensure the best performance, the memory manager interfaces directly with the Win32 virtual memory API (the VirtualAlloc and VirtualFree functions). The memory manager reserves memory from the operating system in 1Mb sections of address space, and commits memory as required in 16K increments. It decommits and releases unused memory in 16K and 1Mb sections. For smaller blocks, committed memory is further suballocated. Memory manager blocks are always rounded upward to a 4-byte boundary, and always include a 4-byte header in which the size of the block and other status bits are stored. This means that memory manager blocks are always double-word-aligned, which guarantees optimal CPU performance when addressing the block. The System unit provides two procedures, GetMemoryManager and SetMemoryManager, that allow applications to intercept low-level memory manager calls. The memory manager maintains two status variables, AllocMemCount and AllocMemSize, which contain the number of currently allocated memory blocks and the combined size of all currently allocated memory blocks. Applications can use these variables to display status information for debugging. The System unit also provides a function called GetHeapStatus that returns a record containing detailed memory-manager status information. Variables Global variables are allocated on the application data segment and persist for the duration of the program. Local variables (declared within procedures and functions) reside in an application's stack. Each time a procedure or function is called, it allocates a set of local variables; on exit, the local variables are disposed of. Compiler optimization may eliminate variables earlier. On Win32, an application's stack is defined by two values: the minimum stack size and the maximum stack size. The values are controlled through the $MINSTACKSIZE and $MAXSTACKSIZE compiler directives, and default to 16,384 (16K) and 1,048,576 (1Mb) respectively. An application is guaranteed to have the minimum stack size available, and an application's stack is never allowed to grow larger than the maximum stack size. If there is not enough memory available to satisfy an application's minimum stack requirement, Windows will report an error upon attempting to start the application. If a Win32 application requires more stack space than specified by the minimum stack size, additional memory is automatically allocated in 4K increments. If allocation of additional stack space fails, either because more memory is not available or because the total size of the stack would exceed the maximum stack size, an EStackOverflow exception is raised. (Stack overflow checking is completely automatic. The $S compiler directive, which originally controlled overflow checking, is maintained for backward compatibility.) Dynamic variables created with the GetMem or New procedure are heap-allocated and persist until they are deallocated with FreeMem or Dispose. Long strings, wide strings, dynamic arrays, variants, and interfaces are heap-allocated, but their memory is managed automatically Compartilhar este post Link para o post Compartilhar em outros sites
silvarudo 0 Denunciar post Postado Agosto 4, 2010 Procurando na internet, achei um exemplo que pode dar certo. Trata-se do "Memory Mapped". Como os Arrays são verdadeiramente grandes e, nem sempre necessitarei dele todo, talvez fosse mais fácil grává-los em arquivos bynários depois abri-los pra preencher um array dinâmico. Esse código talvez deixe o programa mais rápido e com menos memória. If your really want to read a binary file fast, let windows worry about buffering ;-) by using Memory Mapped Files. Using this you can simple map a file to a memory location an read like it's an array. Your function would become: procedure openfile(fname:string); var InputFile: TMappedFile; begin InputFile := TMappedFile.Create; try InputFile.MapFile(fname); SetLength(dataarray, InputFile.Size); Move(PByteArray(InputFile.Content)[0], Result[0], InputFile.Size); finally InputFile.Free; end; end; But I would suggest not using the global variable dataarray, but either pass it as a var in the parameter, or use a function which returns the resulting array. procedure ReadBytesFromFile(const AFileName : String; var ADestination : TByteArray); var InputFile : TMappedFile; begin InputFile := TMappedFile.Create; try InputFile.MapFile(AFileName); SetLength(ADestination, InputFile.Size); Move(PByteArray(InputFile.Content)[0], ADestination[0], InputFile.Size); finally InputFile.Free; end; end; The TMappedFile is from my article Fast reading of files using Memory Mapping, this article also contains an example of how to use it for more "advanced" binary files. O PROBLEMA É QUE NÃO ENTENDI TUDO!! HEHE!! Compartilhar este post Link para o post Compartilhar em outros sites