*mem = AllocateMemory(1024)
Debug *mem
Debug MemorySize(*mem) ; Valid memory ID here
FreeMemory(*mem)
Debug *mem
Debug MemorySize(*mem) ; Not a valid memory ID anymore
Essentially what I am wanting to do is create a procedure that takes a memory ID as a parameter, but I want to verify that it is valid so that it can return with a fail code if necessary.
*MemoryID = AllocateMemory(1000)
*Pointer = *MemoryID
CopyMemoryString("Hello ", @*Pointer)
CopyMemoryString("World")
*NewMemoryID = ReAllocateMemory(*MemoryID, 2000) ; need more memory
If *NewMemoryID
; work with *NewMemoryID now with size 2000
;
Debug "The old content is still here:"
Debug PeekS(*NewMemoryID)
FreeMemory(*NewMemoryID)
Else
; resizing failed, keep working with *MemoryID (size 1000)
;
FreeMemory(*MemoryID)
EndIf
Example from help
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Unless I'm missing something (which is entirely possible), I don't see how that solves my problem. I've updated my example to give a better reflection of what I am trying to achieve:
Procedure MyProc(*mem)
Debug *mem
If *mem ; I want to check if *mem is valid
Debug MemorySize(*mem)
Else
ProcedureReturn 0 ; *mem not valid, so fail
EndIf
EndProcedure
*mem = AllocateMemory(1024)
MyProc(*mem) ; Valid memory ID here
FreeMemory(*mem)
MyProc(*mem) ; Not a valid memory ID anymore
Procedure MyProc(*mem)
If *mem ; I want to check if *mem is valid
Debug "*mem is valid"
Else
Debug "*mem isn't valid"
ProcedureReturn 0 ; *mem not valid, so fail
EndIf
EndProcedure
*mem = AllocateMemory(1024)
MyProc(*mem) ; Valid memory ID here
FreeMemory(*mem) : *mem = 0
MyProc(*mem) ; Not a valid memory ID anymore
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
But the procedure would still produce an error if garbage is put into the parameter. I want to check if what is passed is valid, something like an IsMemory(*mem) function.
Kind regards,
Francis
Last edited by Dreamland Fantasy on Thu Apr 17, 2014 12:43 am, edited 1 time in total.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Procedure SafePlace()
MessageRequester("Warning", "An error has been encountered, and the application will be closed.")
SetUnhandledExceptionFilter_(#Null)
End
EndProcedure
Procedure UnhandledExceptionFilter(*ep.EXCEPTION_POINTERS)
*ep\ExceptionRecord\ExceptionFlags = 0
*ep\ContextRecord\Eip = @SafePlace()
ProcedureReturn #EXCEPTION_CONTINUE_EXECUTION
EndProcedure
SetUnhandledExceptionFilter_(@UnhandledExceptionFilter())
RaiseException_(#EXCEPTION_ACCESS_VIOLATION, #EXCEPTION_NONCONTINUABLE, #Null, #Null)
SetUnhandledExceptionFilter_(#Null)
Last edited by JHPJHP on Thu Apr 17, 2014 5:19 pm, edited 2 times in total.
If you're not investing in yourself, you're falling behind.
That version of code is Windows x86 platforms only.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Thanks JHPJHP for those examples, but I need something that is going to be compatible across multiple platforms.
My current solution is to use a structure to store the memory pointer and other details, and check if these are valid. It seems to work, but I'll need to test it further to be sure that it will work in all cases.