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


Groups > comp.lang.c > #67109

Re: trouble of static working-data-buffers size assumption

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: trouble of static working-data-buffers size assumption
Date 2015-08-11 13:41 +0100
Organization A noiseless patient Spider
Message-ID <87614matfi.fsf@bsb.me.uk> (permalink)
References <7654f359-9404-4818-a877-b3a0d5c32d05@googlegroups.com> <b292d473-024c-465c-917e-54bc594ec37b@googlegroups.com> <mqalim$298$1@dont-email.me> <Xcdyx.22957$Q_3.4315@fx07.iad> <28fd1dc9-09f8-4218-b019-73b1fb2b28f5@googlegroups.com>

Show all headers | View raw


Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
<snip>
> Though the paradigm is
>
> TOUR *tspsetup(int N)
> {
>    TOUR *answer = malloc(sizeof(TOUR));
>    if(!answer)
>        goto out_ofmemory;
>    answer->whizzymatrix = 0;
>    answer->whizzytourbuffer = 0;
>
>    answer->whizzymatrix = malloc(N * N * sizeof(CELL));
>    if(!answer->whizzymatrix)
>      goto out_of_memory;
>    answer->whizzytourbuffer = malloc(N *  N * N * sizeof(WHIZZYTOUR));
>    if(!answer->whizzytour_buffer)
>        goto out_of_memory;

     return answer;
    
>
>   out_of_memory;
(: rather than ;)
>      killtour(answer);
>      return 0;
> }

Alternatively (just so that it's clear there are other ways):

  TOUR *tpsetup(size_t N)
  {
      TOUR *answer = malloc(sizeof *answer);
      if (answer) {
          answer->whizzymatrix =
              malloc(N * N * sizeof *answer->whizzymatrix);
          answer->whizzytourbuffer =
              malloc(N * N * N * sizeof *answer->whizztourbuffer);
          if (answer->whizzymatrix && answer->whizzytourbuffer)
              return answer;
      }
      killtour(answer);
      return 0;
  }

<snip>
-- 
Ben.

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


Thread

trouble of static working-data-buffers size assumption fir <profesor.fir@gmail.com> - 2015-08-10 07:42 -0700
  Re: trouble of static working-data-buffers size assumption fir <profesor.fir@gmail.com> - 2015-08-10 07:48 -0700
    Re: trouble of static working-data-buffers size assumption Ken Brody <kenbrody@spamcop.net> - 2015-08-10 13:05 -0400
      Re: trouble of static working-data-buffers size assumption fir <profesor.fir@gmail.com> - 2015-08-10 10:21 -0700
        Re: trouble of static working-data-buffers size assumption fir <profesor.fir@gmail.com> - 2015-08-10 10:52 -0700
      Re: trouble of static working-data-buffers size assumption fir <profesor.fir@gmail.com> - 2015-08-10 11:25 -0700
        Re: trouble of static working-data-buffers size assumption Ken Brody <kenbrody@spamcop.net> - 2015-08-11 11:25 -0400
      Re: trouble of static working-data-buffers size assumption Richard Damon <Richard@Damon-Family.org> - 2015-08-10 22:36 -0400
        Re: trouble of static working-data-buffers size assumption Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-08-10 22:54 -0700
          Re: trouble of static working-data-buffers size assumption Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-11 13:41 +0100
            Re: trouble of static working-data-buffers size assumption Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-08-11 08:27 -0700
  Re: trouble of static working-data-buffers size assumption David Brown <david.brown@hesbynett.no> - 2015-08-10 18:22 +0200

csiph-web