home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / amiga / programm / 18521 < prev    next >
Encoding:
Text File  |  1993-01-11  |  2.4 KB  |  66 lines

  1. Path: sparky!uunet!gatech!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!bgsuvax!uoft02.utoledo.edu!jupiter!mneylon
  2. Newsgroups: comp.sys.amiga.programmer
  3. Subject: Re: HELP: malloc() and system dependancy
  4. Message-ID: <1993Jan11.144745.999@uoft02.utoledo.edu>
  5. From: mneylon@jupiter.cse.utoledo.edu (Michael Neylon)
  6. Date: 11 Jan 93 14:47:44 EST
  7. References: <C0p18n.DML@unx.sas.com>
  8. Nntp-Posting-Host: jupiter.cse.utoledo.edu
  9. Lines: 55
  10.  
  11. walker@twix.unx.sas.com (Doug Walker) writes:
  12. : In article <1993Jan10.203944.979@uoft02.utoledo.edu>, mneylon@jupiter.cse.utoledo.edu (Michael Neylon) writes:
  13. : |> My friend and I are working together on producing a flashcard program.  He
  14. : |> has SAS/C 6.0, I have 6.1.  Today, he gave me some code and a executable.
  15. : |> The output seems to work fine on his machine.  However, when I try to run
  16. : |> the same executable, there is some memory conflict cause the font gets all
  17. : |> screwed up.  
  18. : |> 
  19. : |> I figure it is a malloc() call in his program.  He has defined it safely
  20. : |> according to standards.  Now, is malloc() safe to use on any system?
  21. : |> 
  22. : |> He has a 2000 w/ 2.1, very little in the way of commodities ( a screen 
  23. : |> blanker is all).  I have a 500 w/ 2.1, and lots of extra programs at the top,
  24. : |> including Nickprefs, CopperPrefs, TM2.0, ToolsDaemon 2.0b, MFR, ASwarm3
  25. : |> MagIcon, and use csh for the shell.
  26. : malloc() is totally safe on any system.  Why do you suspect it of
  27. : causing the problem?  Memory-trashing bugs often exhibit wildly
  28. : different behavior on different machines.
  29. : If you suspect a memory trash, I recommend using the memlib utility
  30. : routines found in the SC:EXTRAS/MEMLIB drawer to help track it
  31. : down.
  32. Well, now my friend is getting the same problem.  The basic struct of the
  33. program is this...
  34.  
  35. struct card {
  36.     char a[40];
  37.     char q[40];
  38.     int flags;
  39. };
  40.  
  41. main() {
  42.     struct card *ccp;
  43.  
  44.     ...
  45.  
  46.     if((ccp=malloc(deck_size()*sizeof(struct card)))==NULL) exit(1);
  47.  
  48.     ...Fill ccp[] array
  49.     ...Read back ccp[] array
  50.  
  51.     free(ccp);
  52.     }
  53.  
  54. It seems that the memory gets trashed at some point after allocation, because
  55. we have verified that the file is read properly, but otherwise we have no clue.
  56.  
  57. -- 
  58. Michael Neylon   aka Masem the Great and Almighty Thermodynamics GOD!
  59.       //         | Senior, Chemical Engineering, Univ. of Toledo
  60.   \\ // Only the |   Summer Intern, NASA Lewis Research Center
  61. \  \X/   AMIGA!  |         mneylon@jupiter.cse.utoledo.edu           /
  62.