Re: loading csv-files: too much memory-consumption
- From: pjb@xxxxxxxxxxxxxxxxx (Pascal J. Bourguignon)
- Date: Tue, 06 Oct 2009 15:54:12 +0200
Rainer Joswig <joswig@xxxxxxx> writes:
I still have no idea how likely it is that the stack in ECL will
contain an assumed pointer to heap data. Is that something that will
happen very rarely or only in special situations? What kind
of data on the stack would trigger it? (assuming that heap
address begin at some point and end, ...).
First, stack addresses are a limited range (or ranges) of integers.
On a linux system try on your (sh-like) shell:
cat /proc/$$/maps
to see a typical memory map, or try:
(com.informatimago.common-lisp.interactive:cat
(format nil "/proc/~D/maps"
#+clisp (posix:process-id)
#-clisp
(progn
(cerror "return your pid please" "How do we get the pid here?")
(format *query-io* "Pid? ")
(read *query-io*))))
to see the memory map of your lisp implementation.
Now, if only initialized data was stored on the stack (and in the live
parts of the heap) then basically the probability to take some bits
for a pointer in the heap would in general be proportional to the size
of the heap vs. the size of the address space.
However, in non-controlled programming languages (or "optimization"
levels), not all data is initialized. In that case it is rather more
probably to have a true pointer in random places, because the legal
adresses are already stored in memory, and are therefore subject of
copy and reuse in non-initialized variables.
malloc() allocates size bytes and returns a pointer to the
allocated memory. The memory is not cleared.
Therefore if a function written in a uncontrolled programming language
use this kind of non-initializing memory allocation, the probability
that this memory block contains an address previously left by a freed
structure that contained that pointer is rather higher.
So, basically, if you use half of your address space for heap, the
probability that a random word points in it is p=1/2. But if you use
C, that probability becomes much bigger.
Now, if you restrict the valid pointers to the first byte of each
allocated memory blocks, and count for an average of 8 or 16 byte per
memory block, obviously you reduce the default probably to 1/16 or
1/32, but this doesn't change much the higher probability of having
unerased valid pointers with unmanaged programming languages.
If some data on the stack is interpreted as a pointer and the
pointer would point to the middle of a large array on the
heap. Would that object then be recognized as a piece of a large
array, or would it cause marking of again non-precisely recognized
data?
It has been mentionned for ECL that only the address of the first byte
of each memory block is taken as a live pointer. This is somewhat
non-conservative, but we can impose this rule to C programs trying to
embed ECL: do not keep offsetted pointers to lisp data, or in packed
structures, etc.
By the same token, if you have a low-level primitive to convert a
reference to a lisp object into an integer containing its address,
you cannot count on the garbage collector to retain that lisp object
if no other reference remains.
--
__Pascal Bourguignon__
.
- Follow-Ups:
- Re: loading csv-files: too much memory-consumption
- From: Juanjo
- Re: loading csv-files: too much memory-consumption
- References:
- loading csv-files: too much memory-consumption
- From: Bernd
- Re: loading csv-files: too much memory-consumption
- From: Madhu
- Re: loading csv-files: too much memory-consumption
- From: Bernd
- Re: loading csv-files: too much memory-consumption
- From: Madhu
- Re: loading csv-files: too much memory-consumption
- From: Bernd
- Re: loading csv-files: too much memory-consumption
- From: Rainer Joswig
- Re: loading csv-files: too much memory-consumption
- From: Juanjo
- Re: loading csv-files: too much memory-consumption
- From: Rainer Joswig
- Re: loading csv-files: too much memory-consumption
- From: Juanjo
- Re: loading csv-files: too much memory-consumption
- From: Rainer Joswig
- Re: loading csv-files: too much memory-consumption
- From: Juanjo
- Re: loading csv-files: too much memory-consumption
- From: Rainer Joswig
- loading csv-files: too much memory-consumption
- Prev by Date: Re: A chat bot in Common Lisp
- Next by Date: Re: Avoiding LispWorks Personal annoyances
- Previous by thread: Re: loading csv-files: too much memory-consumption
- Next by thread: Re: loading csv-files: too much memory-consumption
- Index(es):
Relevant Pages
|