Alasdair McAndrew on Sat, 23 Jun 2012 17:14:13 +0200
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
A question about memory and garbage collection
- To: email@example.com
- Subject: A question about memory and garbage collection
- From: Alasdair McAndrew <firstname.lastname@example.org>
- Date: Sun, 24 Jun 2012 01:14:05 +1000
- Delivery-date: Sat, 23 Jun 2012 17:14:13 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Is/hiHxF1ylJoxO/f5rRo2eHFKHmOIFjYIcAtZXrrEg=; b=KdXDwrJCA49Dj86+F85JC+Nb0DOD98YgxDOkuIsii4nKR3tQqrUil9Hjslat/2Jk3H Vp+Wt1sXoZJHJqYH26m0VSlusPfNC77cSUyK04tzKYAyEpzMvUpRWEZik4gN3IuKf5Yw tvsYHfZzxmhAUepVGOg1Tg2cM2qxRRtK9SWgnONQvZHUurHP1aamJsNwLAGYLbEvLO0E FGHNJVCb9AMFyTKUC6eIHMVJpkKo1ACIL0Ck6Is+z9x7KddBeVNX4B4IO9L4RddiOtfu EKToH2Q+Gwe2Q5QMq87/tCNNu6WbLu1iDh2v5VX0Kx5uKxGJgW7dseYyIpvReuReJkRi MeWA==
I am testing some prng routines, and using PARI to speed up the computations.
My basic routine contains something like
int main(int argc, char *argv)
n = gp_read_str(argv);
i = gen_0;
GEN t = prng();
Here prng() is a function which returns a GEN. Basically it takes a value x, does some computations (using a few auxiliary variables), and returns an updated value. It may do this 10^12 times. Clearly I need to have some sort of memory management: once a value x is updated and used to create the next value, it is needed no longer. So I need some way of removing the previous value of x so that the stack doesn't overflow.
Here's an example of the sort of prng() I might use (I'm not actually using this one, but you get the idea):
y = Fp_pow(x,7,p);
x = y;
(where p is a GEN set to a large prime). How do I keep the memory and stack at a reasonable size? I've read the manual, and experimented with cgiv, and with avma, gerepile etc, but so far none of my attempts has worked.
I'm sorry if this is a stupid question, but I am quite new to PARI, and not a very experienced C programmer: most of my work up to now has been in high level languages (Maple, Sage, Maxima, etc).