Last active
November 23, 2017 02:48
-
-
Save initbar/41686c666263f643da0aff08e93f16d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
from prettytable import PrettyTable | |
MEMORY_UPPER_LIMIT = float(16 * 2<<39) | |
a = -2 | |
b = a + 1 | |
print('a = %s (%s)' % (a, hex(id(a)))) | |
print('b = %s (%s)' % (b, hex(id(b)))) | |
print('a,b offset = %s' % hex(id(a) - id(b))) # 24 bytes offset??? | |
x = a | |
y = b | |
t = t = PrettyTable(['mem_addr', 'int', 'offset', 'direction']) | |
# while id(x)>=id(y): | |
for i in range(258): | |
x += 1 | |
y += 1 | |
offset = id(x) - id(y) | |
direction = ( | |
'high -> low' | |
if offset > 0 | |
else 'low -> high') | |
try: t.add_row([ | |
'%s (%0.16f%%)' % (hex(id(x)), x / MEMORY_UPPER_LIMIT), | |
x, | |
'%s B' % (offset), | |
direction]) | |
except Exception as error: | |
raise error | |
# do it once more | |
x += 1 | |
y += 1 | |
offset = id(x) - id(y) | |
direction = ( | |
'high -> low' | |
if offset > 0 | |
else 'low -> high') | |
try: t.add_row([ | |
'%s (%0.16f%%)' % (hex(id(x)), x / MEMORY_UPPER_LIMIT), | |
x, | |
'%s B' % (offset), | |
direction]) | |
except Exception as error: | |
raise error | |
finally: | |
print (t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment