- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Hi,
I have a crash during deallocation of a derived type. I found a thread that may describe a relevant debugging step for me:
community.intel.com/t5/Intel-Fortran-Compiler/heap-corruption-error/m-p/890765#M78197
My question is: how to do the same (find the hidden allocation header) for a derived type instead of an array? For the array it was done by associating a pointer to just after the last element.
[edit to make a proper link]
Link copiado
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
LOC(yourUDT) will give you the address of the data portion of the UDT. Preceding this will be one or more pointer sized elements for the allocation header. What is present, depends on the heap manager. There is at least one for a link, potentially a second for count (in case of array), potentially a third for padding (in case of aligned allocation), possibly a fourth for debugging, ...
You may have to experiment to figure out the header.
Also, the heap manager (unless the TBB scalable allocator is used) is the CRT library heap. You can link in the debug version of the heap and then use the C heap diagnostic functions. See:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-debug-heap-details?view=msvc-170
https://dmalloc.com/ (I havn't seen usages of this)
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/heapchk?view=msvc-170
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/heapwalk?view=msvc-170
Jim Dempsey
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Thanks.
I was able to print out the integer values of the allocation header elements by defining the variables
INTEGER(KIND=INT_PTR_KIND()) :: iAllocHeader
INTEGER(KIND=INT_PTR_KIND()) :: allocHeader
POINTER (iAllocHeader, allocHeader)
Then print out values for n = 1,2,... by
iAllocHeader = LOC(myObject) - INT_PTR_KIND() * n
write(*,*) "Allocation header",allocHeader
I could see that the value for n=3 was changing slightly at some point, but other objects that deallocate without problem also had a change on this on. Other values were not changing.
I'll probably have to look at your links to check the heap more thoroughly.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Also, make sure you do a Debug build with all build and runtime diagnostics enabled.
Jim Dempsey
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
I have done that too, also with another compiler which is generally very good at catching memory issues, but it works fine in the debug build
- Subscrever fonte RSS
- Marcar tópico como novo
- Marcar tópico como lido
- Flutuar este Tópico para o utilizador atual
- Marcador
- Subscrever
- Página amigável para impressora