Skip to content

Instantly share code, notes, and snippets.

@initbar
Last active November 23, 2017 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save initbar/41686c666263f643da0aff08e93f16d7 to your computer and use it in GitHub Desktop.
Save initbar/41686c666263f643da0aff08e93f16d7 to your computer and use it in GitHub Desktop.
#!/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