home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5274 < prev    next >
Encoding:
Text File  |  1992-08-12  |  2.2 KB  |  61 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!s5!is1.is.morgan.com!is0.is.morgan.com!robt
  3. From: robt@is.morgan.com (Rob Torop)
  4. Subject: usersub
  5. Message-ID: <ROBT.92Aug12113621@idt101.is.morgan.com>
  6. Sender: news@is.morgan.com
  7. Nntp-Posting-Host: idt101
  8. Organization: Morgan Stanley & Company
  9. Distribution: comp.lang.perl
  10. Date: Wed, 12 Aug 1992 16:36:21 GMT
  11. Lines: 48
  12.  
  13. I've been fooling around a lot with usersub.  I've managed to hook
  14. some things in, but I think I've got a memory leak.  I ran a perl
  15. program to check for leaks by calling my usersub in an infinite loop.
  16. It ran out of memory after around 180,000 calls.  Here's my code - if
  17. there's something obviously wrong, I'd really appreciate some advice!
  18.  
  19. p.s.  do_tval does *no* memory allocation at all.
  20.  
  21. case US_tv:
  22.     if (items < 7)
  23.       fatal("Usage &tv($descr,$ul,$strike,$tex,$vola,$rfr,$divyld [,$hints])");
  24.     else {
  25.         char *   descr  = (char *) str_get(st[1]);
  26.         double   ul     = (double) str_gnum(st[2]);
  27.         double   strike = (double) str_gnum(st[3]);
  28.         double   tex    = (double) str_gnum(st[4]);
  29.         double   vola   = (double) str_gnum(st[5]);
  30.         double   rfr    = (double) str_gnum(st[6]);
  31.         double   divyld = (double) str_gnum(st[7]);
  32.         TvHints  hints  = 0;
  33.         TvTheoValue tv;
  34.  
  35.         if (items > 7) 
  36.             hints = (TvHints) str_gnum(st[8]);
  37.             
  38.         if (!do_tval(descr,ul,strike,tex,vola,rfr,divyld, hints, &tv))
  39.             fatal("tv: Valuation error");
  40.  
  41.         astore(stack, sp+7, NULL);
  42.         st[0] = str_2mortal(str_nmake(tv.thVal[0]));
  43.         st[1] = str_2mortal(str_nmake(tv.delta[0]));
  44.         st[2] = str_2mortal(str_nmake(tv.gamma[0]));
  45.         st[3] = str_2mortal(str_nmake(tv.theta[0]));
  46.         st[4] = str_2mortal(str_nmake(tv.kappa[0]));
  47.         st[5] = str_2mortal(str_nmake(tv.rho[0]));
  48. #ifdef RHODIV
  49.         st[6] = str_2mortal(str_nmake(tv.rhodiv[0]));
  50. #else
  51.         st[6] = str_2mortal(str_nmake(0.0));
  52. #endif
  53.         return sp + 7 - 1;
  54.     }
  55. --
  56. -- Rob Torop
  57.  
  58. +---------------------------------------------------------------------+
  59. | The views expressed here are neither mine nor those of my employer. |
  60. +---------------------------------------------------------------------+
  61.