The result of 512*1024 becomes 0

try just "unsigned long"

Edit: that's not it

I'm playing with it, but not using the library