Skip to content

Instantly share code, notes, and snippets.

@initbar
Last active Nov 23, 2017
Embed
What would you like to do?
#!/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