From simon.urbanek at r-project.org  Thu Jun  9 02:40:21 2011
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Wed, 8 Jun 2011 20:40:21 -0400
Subject: [Rd] Ctrl-C of functions that allocated mem
In-Reply-To: <20110609000627.GA3482@siouxsie>
References: <20110609000627.GA3482@siouxsie>
Message-ID: <FF0548F3-A51E-426E-8D18-367E34FD61E2@r-project.org>


On Jun 8, 2011, at 8:06 PM, oliver wrote:

> 
> Hello,
> 
> 
> what happens, when a function (R-extension in C), that allocated memory
> (strdup(), malloc()/calloc() and so on), and is used in interactive mode, then
> will be stopped via Ctrl-C?
> 
> I would assume that there remains allocated memory,
> which is not usable and also not accessable (hence no
> way to free it).
> 
> Are there any mechanisms in R that could help in rolling
> back the allocation?
> 

Yes, if you read R-exts:
http://r.research.att.com/man/R-exts.html#Memory-allocation
you would know that you're not supposed to use malloc/calloc at all and if you allow interruption ("regular" C code does not) R_alloc does what you asked about.

Cheers,
Simon


> Normally in an interactive session "some memory" might not be a problem,
> because it will be run shortly; but I prefer clean solutions.
> And also, if it's much mem, which is allocated each time, and one does many
> trials and Ctr-C's, even an interactive session might eat a lot of mem.
> 
> So I would be interested in a solution to this (potential) problem.
> 
> 
> Ciao,
>   Oliver
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 



[Rd] Ctrl-C of functions that allocated mem
Simon Urbanek