Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Calloc of "unsigned char my_bytes[256][256]"

Reply
Thread Tools

Calloc of "unsigned char my_bytes[256][256]"

 
 
M-One
Guest
Posts: n/a
 
      07-06-2003
See subject: how do I calloc (and free the memory, if that's not
free(my_bytes) this?

TIA!
 
Reply With Quote
 
 
 
 
Al Bowers
Guest
Posts: n/a
 
      07-06-2003


M-One wrote:
> See subject: how do I calloc (and free the memory, if that's not
> free(my_bytes) this?
>
> TIA!


A good start on learning how would be to read the faq located at:
http://www.eskimo.com/~scs/C-faq/top.html

Question 6.16 discuss this topic.
http://www.eskimo.com/~scs/C-faq/q6.16.html


--
Al Bowers
Tampa, Fl USA
mailto: http://www.velocityreviews.com/forums/(E-Mail Removed) (remove the x)
http://www.geocities.com/abowers822/

 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      07-06-2003

M-One <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> See subject: how do I calloc (and free the memory, if that's not
> free(my_bytes) this?


Have you tried looking up the documentation for calloc
and free?

#include <stdio.h>
#include <stdlib.h>

int main()
{
unsigned char *my_bytes = calloc(256 * 256, sizeof *my_bytes);
if(my_bytes == NULL)
{
fprintf(stderr, "Cannot allocate memory");
return EXIT_FAILURE;
}

/* whatever */

free(my_bytes);
return EXIT_SUCCESS;
}

-Mike



 
Reply With Quote
 
M-One
Guest
Posts: n/a
 
      07-06-2003
>> See subject: how do I calloc (and free the memory, if that's not
>> free(my_bytes) this?


> Have you tried looking up the documentation for calloc
> and free?


Yes; thanks for the example.
 
Reply With Quote
 
M-One
Guest
Posts: n/a
 
      07-06-2003
> Question 6.16 discuss this topic.
> http://www.eskimo.com/~scs/C-faq/q6.16.html


Thanks for the pointer.
 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      07-07-2003
Al Bowers <(E-Mail Removed)> wrote in message
news:ygMNa.4653$(E-Mail Removed)...

> Al Bowers
> Tampa, Fl USA


Hey Al, how does Lou's hair look?

-Mike (Seattle, WA)




 
Reply With Quote
 
Giuseppe
Guest
Posts: n/a
 
      07-07-2003
On Sun, 06 Jul 2003 14:26:30 GMT, Al Bowers <(E-Mail Removed)>
wrote:
>M-One wrote:
>> > Question 6.16 discuss this topic.
>> > http://www.eskimo.com/~scs/C-faq/q6.16.html

[...]
#include <stdio.h>
#include <stdlib.h>
#define P printf
#define R return
#define F for

#define NROWS 256
#define NCOLUMNS 256


typedef struct ARRAY{
unsigned char **array1;
size_t nrows;
size_t ncolumns;
}ARRAY;


int resizeARRAY(ARRAY *p, size_t nrows, size_t ncolumns);
void freeARRAY(ARRAY *p);


int main(void)
{ ARRAY my={NULL, 0, 0};

if(resizeARRAY(&my, NROWS, NCOLUMNS))
{my.array1[255][255] = 'c';
printf("my.array1[255][555] = \'%c\'\n", my.array1[255][255]);
}

freeARRAY(&my);
return 0;
}


int resizeARRAY(ARRAY* p, size_t nrows, size_t ncolumns)
{ size_t i;
unsigned char **temp;

if( (temp=realloc( p->array1, nrows * sizeof(*temp) )) == NULL )
R 0;
p->array1=temp;
for( i=0; i<nrows; i++ )
{p->array1[i]=malloc( ncolumns * sizeof( *(p->array1[i]) ) );
if(p->array1[i] == NULL)
{F( --i; i!=0; --i)
free( p->array1[i] );
free( p->array1[0] );
free( p->array1 );
R 0;
}
}
p->nrows = nrows ;
p->ncolumns = ncolumns;
return i; /* Ritorna il numero di righe allocate; */
}


void freeARRAY(ARRAY* p)
{ size_t i;

for(i=0; i < p->nrows; i++)
free( p->array1[i] );
free( p->array1 );
p->array1 = 0;
p->ncolumns = 0;
p->nrows = 0;
}


void freeARRAY1(ARRAY* p)
{ size_t i;

for(i=0; i < p->nrows; i++)
free( p->array1[i] );
free( p->array1 );
free(p);
}

 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      07-07-2003
(E-Mail Removed)w (Giuseppe) wrote (07 Jul 2003) in
news:(E-Mail Removed) / comp.lang.c:

> [...]
> #include <stdio.h>
> #include <stdlib.h>
> #define P printf
> #define R return
> #define F for


He's back. And as stupid as ever.




--
Martin Ambuhl
Returning soon to the
Fourth Largest City in America
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      07-07-2003
On Mon, 07 Jul 2003 16:17:23 GMT, in comp.lang.c ,
(E-Mail Removed)w (Giuseppe) wrote:

>On Sun, 06 Jul 2003 14:26:30 GMT, Al Bowers <(E-Mail Removed)>
>wrote:
>>M-One wrote:
>>> > Question 6.16 discuss this topic.
>>> > http://www.eskimo.com/~scs/C-faq/q6.16.html

>[...]
>#include <stdio.h>
>#include <stdlib.h>
>#define P printf
>#define R return
>#define F for


Why do you persist in this obfuscatory stupidity? Do you think it
makes you look clever? Do you think its useful for others? Top Tip: it
makes you look a prat and everyone is ignoring you.

>typedef struct ARRAY{
> unsigned char **array1;
> size_t nrows;
> size_t ncolumns;
>}ARRAY;


By common convention in C, uppercase is reserved for macros,
Microsoft's gratuitous ignoring of that convention notwithstanding.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
 
Reply With Quote
 
Randy Howard
Guest
Posts: n/a
 
      07-07-2003
In article <(E-Mail Removed)>, (E-Mail Removed)w
says...
> #include <stdio.h>
> #include <stdlib.h>
> #define P printf
> #define R return
> #define F for
>
> #define NROWS 256
> #define NCOLUMNS 256
>
>
> typedef struct ARRAY{
> unsigned char **array1;
> size_t nrows;
> size_t ncolumns;
> }ARRAY;



Okay, that's one time too many, I've given up. I don't normally
ever do this, but ...

*plonk*

--
Randy Howard
remove the obvious bits from my address to reply.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
char *fred; char * fred; char *fred; any difference? Ben Pfaff C Programming 5 01-17-2004 07:37 PM
The difference between char a[6] and char *p=new char[6] ? wwj C Programming 24 11-07-2003 05:27 PM
the difference between char a[6] and char *p=new char[6] . wwj C++ 7 11-05-2003 12:59 AM



Advertisments