I'm really sorry for this thread, because it's not the realloc()'s fault but mine. I actually use the shorter size for realloc() but not the longer which I respect, so the problem has been solved....
Type: Posts; User: TalosChen
I'm really sorry for this thread, because it's not the realloc()'s fault but mine. I actually use the shorter size for realloc() but not the longer which I respect, so the problem has been solved....
Well, how can memory pool be corrupted?
free, malloc, realloc or something like this?
Sorry, my program is large. So I cannot give you such code to run for test. But I did write a small test program to test realloc(), and nothing abnormal happened.
for example,
before realloc()
msg_in_all, len: 111, addr: 009C1960
01000029 0301446D 6B1D278D 11AE381E 01000029 0301446D 6B1D278D 11AE381E
FB49D271 EA2D0F36 F97B8E85 EFA0AA64 B5117225...
I remembered that when you call realloc() and the return address is different from the original one, then realloc() should copy the content of the original block to the newly allocated block. But in...
Thanks. I've always learned much here.
Can I free a pointer several times?
Or, can I free a pointer if I don't know whether it has been freed?
MSDN is just reference, it cannot replace a good book. My suggestion is, reading a really good book at beginning will make things much easier.
Sams Teach Yourself C# in 21 Days, a good book for beginners, even newbie to programming.
And Professional C#, a very useful reference book for C# programmers. It almost covers every aspects you...
:-) I know that. It's just an example to explain my question.
Can somebody be kind enough to recommand some good timer tutorials (about how to implement, not to use) to me?
Thanks any way.
No, what I mean is, giving you a pointer ptr, then can you know that if the memory pointed by ptr was once allocated by using malloc(), realloc(), etc. ? For example,
char *ptr1 = &'a';
char...
thanks.
BTW, is there any function can figure out that if a pointer is allocated any memory?
-> Yes. No.
Is Yes said that ptr2 != ptr1 maybe true, and No said that I need not free(ptr1) if it's no longer used?
char *ptr1, *ptr2;
ptr1 = (char *)malloc(m);
ptr2 = ptr1;
ptr2 = (char *)realloc(ptr1, n); // n > m
ptr2 could be different from ptr1 after realloc(), in that case, should I free(ptr1)?
Useful and funny, that's one of the best technique book I've ever seen!
Another book, C Traps and Pitfalls by Andrew Koenig.
Abstract of this book,
"The C language is like a carving knife:...
In Windows, there are actually two chars at the end of a line: \xD and \xA. Note, they exist only in text files. But in *nix, only one: \xA. So you can open a.txt with binary mode, and read a line by...
CategoryType is just NAME of a type, you should use:
currentItem = currentCat->headItem;
replace the currentCat with any pointer you want to really use.
The actual problem is already solved by using select(). But I still wanna know how to implement such a timer that I described. I'm really interesting about it.
array name is unmodifiable, so you should use another pointer that points to "splitbuf".
merge two files, or make two types in one file.
Agree. That's the essence of the problem, what if the function never returns? I think another thread will be needed, but that complicates the problem and a lot should be learned by me. So is there...
But if in general, how can I implement a timeout timer or something else?
Sorry, there's one thing that I forgot to say, that is, I dont wanna a WAIT timer. What I really need is a TIMEOUT timer. For example, the socket function recv(). When it works in block mode, I want...