home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!s5!is1.is.morgan.com!is0.is.morgan.com!robt
- From: robt@is.morgan.com (Rob Torop)
- Subject: usersub
- Message-ID: <ROBT.92Aug12113621@idt101.is.morgan.com>
- Sender: news@is.morgan.com
- Nntp-Posting-Host: idt101
- Organization: Morgan Stanley & Company
- Distribution: comp.lang.perl
- Date: Wed, 12 Aug 1992 16:36:21 GMT
- Lines: 48
-
- I've been fooling around a lot with usersub. I've managed to hook
- some things in, but I think I've got a memory leak. I ran a perl
- program to check for leaks by calling my usersub in an infinite loop.
- It ran out of memory after around 180,000 calls. Here's my code - if
- there's something obviously wrong, I'd really appreciate some advice!
-
- p.s. do_tval does *no* memory allocation at all.
-
- case US_tv:
- if (items < 7)
- fatal("Usage &tv($descr,$ul,$strike,$tex,$vola,$rfr,$divyld [,$hints])");
- else {
- char * descr = (char *) str_get(st[1]);
- double ul = (double) str_gnum(st[2]);
- double strike = (double) str_gnum(st[3]);
- double tex = (double) str_gnum(st[4]);
- double vola = (double) str_gnum(st[5]);
- double rfr = (double) str_gnum(st[6]);
- double divyld = (double) str_gnum(st[7]);
- TvHints hints = 0;
- TvTheoValue tv;
-
- if (items > 7)
- hints = (TvHints) str_gnum(st[8]);
-
- if (!do_tval(descr,ul,strike,tex,vola,rfr,divyld, hints, &tv))
- fatal("tv: Valuation error");
-
- astore(stack, sp+7, NULL);
- st[0] = str_2mortal(str_nmake(tv.thVal[0]));
- st[1] = str_2mortal(str_nmake(tv.delta[0]));
- st[2] = str_2mortal(str_nmake(tv.gamma[0]));
- st[3] = str_2mortal(str_nmake(tv.theta[0]));
- st[4] = str_2mortal(str_nmake(tv.kappa[0]));
- st[5] = str_2mortal(str_nmake(tv.rho[0]));
- #ifdef RHODIV
- st[6] = str_2mortal(str_nmake(tv.rhodiv[0]));
- #else
- st[6] = str_2mortal(str_nmake(0.0));
- #endif
- return sp + 7 - 1;
- }
- --
- -- Rob Torop
-
- +---------------------------------------------------------------------+
- | The views expressed here are neither mine nor those of my employer. |
- +---------------------------------------------------------------------+
-