TestMemory(*mem)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
NikitaOdnorob98
User
User
Posts: 74
Joined: Fri Jun 29, 2012 4:50 pm

TestMemory(*mem)

Post by NikitaOdnorob98 »

Please, add this function

Code: Select all

Procedure.b TestMemory(*Pointer) ;Only Windows
  Protected mbi.MEMORY_BASIC_INFORMATION
  Protected Result.b = #False, dwWrote
  
  dwWrote = VirtualQuery_(*Pointer, @mbi, SizeOf(MEMORY_BASIC_INFORMATION))
  If dwWrote
    If mbi\BaseAddress+mbi\RegionSize >= *Pointer+1
      If mbi\Protect & (#PAGE_READONLY | #PAGE_READWRITE | #PAGE_EXECUTE_READ | #PAGE_EXECUTE_READWRITE)
        Result = #True
      EndIf
    EndIf
  EndIf
  
  ProcedureReturn Result
EndProcedure

*mem = AllocateMemory(10)
If *mem
  Debug TestMemory(*mem)
  FreeMemory(*mem)
EndIf

*mem = Random(100000) ;Random value
Debug TestMemory(*mem)
User avatar
graph100
Enthusiast
Enthusiast
Posts: 115
Joined: Tue Aug 10, 2010 3:17 pm

Re: TestMemory(*mem)

Post by graph100 »

it's not reliable.. 1 time over 5 it answers "1 1"
_________________________________________________
My Website : CeriseCode (Warning : perpetual changes & not completed ;))
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: TestMemory(*mem)

Post by IdeasVacuum »

A random test is of very little value. Tests need to be methodical, cover the entire RAM, mimic application loads, be CPU specific. If you want to test memory Memtest86+: http://www.memtest.org/
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply