Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #76044

Re: how to do this?

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: how to do this?
Date 2015-11-14 18:24 -0500
Organization Self
Message-ID <5647C2C4.9070704@verizon.net> (permalink)
References <n2849g$a6p$1@dont-email.me> <daplreFi0ttU6@mid.individual.net> <n28f7r$pmq$1@dont-email.me>

Show all headers | View raw


On 11/14/2015 06:16 PM, bilsch01 wrote:
>>
>>    // What goes in the last character?
>>
> 
> There's EOF.  9*256=2304
> 
>> Why are you using dynamic allocation here?  You never free what you
>> allocate.
> 
> Yes I see I need to free().  You mention dynamic allocation here - is 
> there another kind I could use?

This is automatic allocation:
	char vec1[9];
	// work with vec1.

This is dynamic allocation:
	char *vec1 = malloc(9);
	if(vec1)
        {
             // work with vec1
             free(vec1);
        }

In general, automatic allocation is a lot simpler. Dynamic allocation
may be necessary if the amount of memory needed is large, because many
systems have far more memory available for dynamic allocation than for
automatic allocation. It's also more appropriate when there's a lot of
variation in the amount of memory that needs to be allocated. Neither of
those reasons apply in this case: 9 bytes is quite tiny, and it's also
fixed.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

how to do this? bilsch01 <king621@comcast.net> - 2015-11-14 12:09 -0800
  Re: how to do this? Rosario19 <Ros@invalid.invalid> - 2015-11-14 21:49 +0100
  Re: how to do this? Ian Collins <ian-news@hotmail.com> - 2015-11-15 10:02 +1300
    Re: how to do this? Ian Collins <ian-news@hotmail.com> - 2015-11-15 10:17 +1300
    Re: how to do this? bilsch01 <king621@comcast.net> - 2015-11-14 15:16 -0800
      Re: how to do this? James Kuyper <jameskuyper@verizon.net> - 2015-11-14 18:24 -0500
        Re: how to do this? bilsch01 <king621@comcast.net> - 2015-11-14 15:30 -0800
          Re: how to do this? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-14 19:01 -0500
          Re: how to do this? James Kuyper <jameskuyper@verizon.net> - 2015-11-14 19:07 -0500
  Re: how to do this? Ian Collins <ian-news@hotmail.com> - 2015-11-15 11:26 +1300
    Re: how to do this? bilsch01 <king621@comcast.net> - 2015-11-14 15:07 -0800
      Re: how to do this? James Kuyper <jameskuyper@verizon.net> - 2015-11-14 18:17 -0500
      Re: how to do this? bilsch01 <king621@comcast.net> - 2015-11-14 15:25 -0800
        Re: how to do this? Ian Collins <ian-news@hotmail.com> - 2015-11-15 13:10 +1300
          Re: how to do this? James Kuyper <jameskuyper@verizon.net> - 2015-11-14 19:21 -0500
            Re: how to do this? Ian Collins <ian-news@hotmail.com> - 2015-11-15 13:24 +1300
        Re: how to do this? James Kuyper <jameskuyper@verizon.net> - 2015-11-14 19:12 -0500
          Re: how to do this? Ian Collins <ian-news@hotmail.com> - 2015-11-15 13:18 +1300
            Re: how to do this? James Kuyper <jameskuyper@verizon.net> - 2015-11-14 19:23 -0500
  Re: how to do this? bilsch01 <king621@comcast.net> - 2015-11-14 15:18 -0800

csiph-web