C Programming Tutorial 64, Memory Functions pt.2 memcpy

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

The "(sizeof(int) * 5)" is evaluated first in this case, and the result becomes the argument to malloc(). In other words, all that is an expression that gets evaluated before the malloc() operation happens. So you can do all kinds of math in there, as long as the resulting expression evaluated to ONE argument. You could say this...

int *myMemory = malloc(sizeof(char)*20 + sizeof(int)*25 - 1);

...and you'll get 119 bytes of memory back (20 + 100 - 1), assuming a 32-bit system.

tcbetka
Автор

Adam Also i have three suggestions if you allow me please, not saying your tut are bad all the contrary are the best that i have seen! and thanks you for this. But i suggest you answer this three questions when discussing your tuts. 1. why is this important 2. when is useful 3. give us an example of where would we use what you are discussing. (doesnt have to be graphically but for example where is malloc used where would we use it and why is so important. Thanks for all this tuts keep the work!

thewhisperinyourears
Автор

according to the man pages, if memcpy overlaps behavior is undefined. It says if you want overlap you should use memmove because it is not destructive. It is used the same way

seal
Автор

Dude you're helping me so much... seriously... Thank you !!

clode
Автор

really nice tutorials adam thanks!, and what about GUIs with C++ ??? ussing Qt or wxWidgets??

gorystylex
Автор

Nice job on the video. Thanks for the review!

tcbetka
Автор

I like you, you're better than my tutor

NadzirNazuwan
Автор

Hey why didnt you need to use typecasting while using malloc I need to do this everytime...

Any tricks ....will be glad to hear

priyanshuKumar-gxri
Автор

what would happen if i allocate more values than the allocated size of heap can take. i tried doing so and it worked fine. plus i free'd the heap memory afterwards and assigned another value to the variable i used the malloc function on. tried printing it and it worked fine. confused now :/

simransingh
Автор

Adams you said malloc only received 1 parameter which is the meory yet you used a function inside malloc and a number thats two params or i am mistaken? malloc(sizeof(int)+5);

thewhisperinyourears
Автор

You should do more Win32 API related videos!

PrfixProducts
Автор

If you want to learn how to use QT check out the channel VoidRealms

iTzAdamX
Автор

Haha Sorry how embarrassing i meant "tuts", i do most of my programming in Java and GUI work in swing, it is a lot more clean and intuitive than Win32 in my opinion even tho Win32 will make faster programs :)

MrHartley
Автор

I've never really done anything with GUIs in C.

iTzAdamX
Автор

al-LOC-ate. Funny to heat that pronounciation. Properly pronounced AL-loc-ate

OneTimWhatley
Автор

You used "Rick" but Rick was conveniently the same size as the other name (4 characters). What happens when it isn't the same size, so a memcpy would start overrwriting the rest of the string? How do we avoid that and shift things over properly? 

onixz
Автор

The tits? Well thanks I guess, haha. I don't know winforms though, I'd prefer to concentrate on topics that are low level, I doubt I'll do any tutorials with GUIs. At least not in C.

iTzAdamX
Автор

A-llocate, not aLLOcate. This is the most petty thing ever, but it's really bugging me for some reason

kyle-silver