Frequently I get an error: Invalid memory access: (write error at address 0). Sometimes the number is higher then 0. Sometimes I get a read-error instead of a write-error.
As an example below code whereas this error appears. It is a WIP (Work In Progress).
The code is pretty simple and straightforward, so no extraordinary things there I think. The section the error appears contains a high variable: 11183522 and this variable is used to define an (also large) array(). When there are no errors, the program runs fine, and I try to approach the array, I get the same error too.
The error in this example appears in the section where it says ";--- locaties in array Locaties$()". It is persistent and comes up every time I run it.
I removed all the overhead (such as opening a window and gadgets). That does not do the trick.
However, if I use only the code up to that section (the rest is not there), this runs normal without the error.
I also write codes whereas this sort of error sometimes appears and next time I run it does not.
-----------------------------------------------------------------------------------------------------
Code: Select all
path$ = "G:\_Cor\PureBasic\Hackers\"
;- scherm openen
OpenWindow(0, 0, 0, 300, 500, "Hackers", #PB_Window_ScreenCentered)
;--- gadgets
TextGadget(0, 10, 10, 150, 20, "")
TextGadget(1, 10, 30, 150, 20, "")
TextGadget(2, 10, 50, 150, 20, "")
TextGadget(3, 10, 70, 150, 20, "")
;- data inlezen
;--- criteria hacker in array CriteriaHackers$()
ReadFile(0, Path$ + "CriteriaHackers.txt")
SetGadgetText(0, "Inlezen criteria hackers")
Dim CriteriaHackers$(0)
AantalCriteria = 0
While Not Eof(0)
regel$ = ReadString(0)
AantalCriteria = AantalCriteria + 1
ReDim CriteriaHackers$(AantalCriteria)
CriteriaHackers$(AantalCriteria) = regel$
Wend
CloseFile(0)
;--- locaties in array Locaties$()
SetGadgetText(1, "Inlezen locaties")
AantalLocaties = 11183522
ReadFile(0, path$ + "Geografie.txt")
Dim Locaties$(AantalLocaties, 2)
For a = 1 To AantalLocaties
regel$ = ReadString(0)
pos1 = FindString(regel$, "#")
pos2 = FindString(regel$, "#", pos1 + 1)
Locaties$(a, 0) = Left(regel$, pos1 - 1)
Locaties$(a, 1) = Mid(regel$, pos1 + 1, pos2 - pos1 - 1)
Locaties$(a, 2) = Right(regel$, Len(regel$) - pos2)
Next a
CloseFile(0)
;--- hackers uit webserv.log filteren en in array Hackers$()
;----- eerst alle IPadressen uit webserv.log halen
SetGadgetText(3, "IPadressen verzamelen")
ReadFile(0, Path$ + "webserv.log")
tmp = 0
Dim tmp$(0)
While Not Eof(0)
regel$ = ReadString(0)
pos = FindString(regel$, " ")
IPadres$ = Left(regel$, pos - 1)
hit = 0
For a = 1 To tmp ; checken of IPadres al voorkomt
If IPadres$ = tmp$(a)
hit = 1
Break
EndIf
Next a
If hit = 0
tmp = tmp + 1
ReDim tmp$(AantalIPadressen)
tmp$(tmp) = IPadres$
EndIf
Wend
CloseFile(0)
;----- IPadressen$ filteren mbv Bots en zo.txt. Hier zit ook ons eigen IPadres in, zowel intern als extern
ReadFile(0, path$ + "Bots en zo.txt")
AantalBots = 0
AantalIPadressen = 0
Dim Bots$(0)
While Not Eof(0)
AantalBots = AantalBots + 1
ReDim Bots$(AantalBots)
Bots$(AantalBots) = ReadString(0)
Wend
Dim IPadressen$(0)
For a = 1 To AantalIPadressen
regel$ = tmp$(a)
hit = 0
For b = 1 To AantalBots
If regel$ = Bots$(b)
hit = 1
Break
EndIf
Next b
If hit = 0
AantalIPadressen = AantalIPadressen + 1
ReDim IPadressen$(AantalIPadressen)
IPadressen$(AantalIPadressen) = regel$
EndIf
Next a
Repeat
WaitWindowEvent()
ForEver
Suggestions on writing this code in a different way are welcome of course, but it would be nice to see a (general?) cause and hopefully a solution (for this particulair code).
An idea....
Windows contains bugs and so does the memorymanager. Could these errors be caused by the memorymanager? In this case there would be nothing I could do about it of course. I use Windows 10, home 64-bits. BTW, the mentioned errors also appeared in previous Windows versions.
Thanks in advance for your feedback. Questions about it? Just ask.
Cheers, Cor
// Code-Tags added (Kiffi)