Mail Archives: djgpp/1999/07/20/05:05:27

From: "Michael Stewart" <mike AT reggin DOT freeserve DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A Structured Problem ?
Date: Tue, 20 Jul 1999 09:32:21 +0100
Organization: (Posted via) Netcom Internet Ltd.
Message-ID: <7n1c6l$14s$>
References: <7mv0te$gq2$1 AT news6 DOT svr DOT pol DOT co DOT uk> <Pine DOT SUN DOT 3 DOT 96 DOT 990719090429 DOT 29235A-100000 AT silver DOT cs DOT umanitoba DOT ca> <7n09p0$9db$1 AT news5 DOT svr DOT pol DOT co DOT uk>
X-Trace: 932459541 1180 (20 Jul 1999 08:32:21 GMT)
X-Complaints-To: abuse AT corp DOT netcom DOT net DOT uk
NNTP-Posting-Date: 20 Jul 1999 08:32:21 GMT
X-Newsreader: Microsoft Outlook Express 4.72.3155.0
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0
Lines: 49
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Paul J G wrote in message <7n09p0$9db$1 AT news5 DOT svr DOT pol DOT co DOT uk>...
>Many thanks to everybody, everythings running fine now. Although perhaps
>could be so kind as to answer these questions for me.
>1) How would I use the free command to free up one of the shape
>or to delete
>    the whole structure ?.

To delete a structure created with malloc you use the free function.

char *test;
test = (char *) malloc (10);
free (test);

So using your shape variables

free (shape[shape_no].xpoint);
free (shape[shape_no].ypoint);

>2) Both Michael and Ed used slightly different malloc commands, whats the
>difference ?.

The code I posted used a cast to tell the compiler that the allocated memory
will be used as float*. Ed didn't use a cast.

malloc returns void* and by using a cast it'll prevent the compiler
complaining about converting between types. It should be quite safe to use
the memory without the cast though.

>3) If I am writing for a machine with 32 megs and want to use, say 3 megs
>for holding my shape data in would I use FARMALLOC command instead ?.

Nope. (from the FAQ) In DJGPP you use a flat address space with no
segmentation, so you don't need far pointers in the sense they are used in
16-bit code.

So if you want to allocate 3mb the all you need to do is:

char *bigmem;
bigmem = (char *) malloc (3 * 1024 * 1024);

Michael Stewart

- Raw text -

  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019