10-15-2005
When to use Malloc?
Hi!
I hope this is the correct forum to post the question even if I'm a newbie...
I am a C-newbie (and really on the edge to be a C-addict
) and have a question.
When should I use malloc?
To state it differently, when should I NOT use malloc?
For instance, if I have an array of chararray/string pointers . Should I allocate space for both the array AND the strings?
Thank you for reading my question.
This really has been bugging me lately...
Tonje
10 More Discussions You Might Find Interesting
1. Programming
1 . Thanks everyone who read the post.
2 . the programe is that :
#include <stdio.h>
#include <string.h>
void do_it(char *p)
{
p = (char *) malloc(100);
(void )strcpy(p,"1234");
}
int main(void)
{
char *p;
do_it(p);
(void )printf("p = %s \n",p); (1 Reply)
Discussion started by: chenhao_no1
1 Replies
2. Programming
hello sir
since by mentioning a integer pointer and storing the integers
by incrementing the pointer value
then what is the purpose of malloc?
u can decalre it as
in t *p;
several integers can be stored by incrementing the value of p,
hence what is the diffrence between this... (2 Replies)
Discussion started by: rajashekaran
2 Replies
3. Programming
Some one please explain me what is Dynamic memory allocation and the use of malloc() function.How do we allocate memory dynamically and also the other way? (3 Replies)
Discussion started by: rash123
3 Replies
4. Programming
Hey Guys
I am trying to implement the malloc function for my OS class and I am having a little trouble with it. I would be really grateful if I could get some hints on this problem.
So I am using a doubly-linked list as my data structure and I have to allocate memory for it (duh...). The... (1 Reply)
Discussion started by: Gambit_b
1 Replies
5. UNIX for Advanced & Expert Users
Hey Guys
Some of my friends have got together and we are trying to write a basic kernel similar to Linux. I am trying to implement the malloc function in C and I am using a doubly linked list as the primary data structure. I need to allocate memory for this link list (duh...) and I don't feel... (2 Replies)
Discussion started by: rbansal2
2 Replies
6. Programming
Why when using realloc, john is reversed 3 times but not the other 2 names ? But if I use malloc, then the 3 names are reversed correctly ? (but then there is a memory leak)
How can I reverse all 3 names without a memory leak ?
char *BUFFER = NULL;
char *STRREVERSE(const char *STRING)
{... (5 Replies)
Discussion started by: cyler
5 Replies
7. UNIX for Dummies Questions & Answers
Do kmalloc and malloc allocate from same heap ? (3 Replies)
Discussion started by: dragonpoint
3 Replies
8. Programming
Hi i found code in google how to malloc an 2D array and i tried that :
#include<stdio.h>
#include<stdlib.h>
int **A;
int **B;
int main(int argc,char *argv)
{
printf("name of text : %s\n",argv);
//read arrays
int i,j;
int l,m;
int M,n;
FILE *fp;
fp=fopen(argv,"r");
... (0 Replies)
Discussion started by: giampoul
0 Replies
9. Programming
Which one is faster among malloc and new?
My understanding is that since new also has to call constructors after allocating memory it must be slower than malloc.
Am I correct? (1 Reply)
Discussion started by: rupeshkp728
1 Replies
10. UNIX for Dummies Questions & Answers
Good day! I'm a newbie in C. I'm trying to get an unlimited input from the user using malloc then printing the inputs after the user presses enter. My code works, but there's a warning that I don't know how to fix. Please help me. Thank you.
Here's my code:
#include <stdio.h>
#include... (6 Replies)
Discussion started by: eracav
6 Replies
LEARN ABOUT REDHAT
net::dns::question
Net::DNS::Question(3) User Contributed Perl Documentation Net::DNS::Question(3)
NAME
Net::DNS::Question - DNS question class
SYNOPSIS
"use Net::DNS::Question"
DESCRIPTION
A "Net::DNS::Question" object represents a record in the question section of a DNS packet.
METHODS
new
$question = Net::DNS::Question->new("example.com", "MX", "IN");
Creates a question object from the domain, type, and class passed as arguments.
qname, zname
print "qname = ", $question->qname, "
";
print "zname = ", $question->zname, "
";
Returns the domain name. In dynamic update packets, this field is known as "zname" and refers to the zone name.
qtype, ztype
print "qtype = ", $question->qtype, "
";
print "ztype = ", $question->ztype, "
";
Returns the record type. In dymamic update packets, this field is known as "ztype" and refers to the zone type (must be SOA).
qclass, zclass
print "qclass = ", $question->qclass, "
";
print "zclass = ", $question->zclass, "
";
Returns the record class. In dynamic update packets, this field is known as "zclass" and refers to the zone's class.
print
$question->print;
Prints the question record on the standard output.
string
print $qr->string, "
";
Returns a string representation of the question record.
data
$qdata = $question->data($packet, $offset);
Returns the question record in binary format suitable for inclusion in a DNS packet.
Arguments are a "Net::DNS::Packet" object and the offset within that packet's data where the "Net::DNS::Question" record is to be stored.
This information is necessary for using compressed domain names.
COPYRIGHT
Copyright (c) 1997-2002 Michael Fuhr. All rights reserved. This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
SEE ALSO
perl(1), Net::DNS, Net::DNS::Resolver, Net::DNS::Packet, Net::DNS::Update, Net::DNS::Header, Net::DNS::RR, RFC 1035 Section 4.1.2
perl v5.8.0 2002-10-12 Net::DNS::Question(3)