Похожие чаты

What is the necessity of type-casting the pointer in malloc? Does

Realloc copy the whole memory previously allocated using malloc into a new memory location in O(n) time complexity? (Yes/No)

10 ответов

27 просмотров

malloc(3) gives you a void* , you must specify the type that you allocated memory for it.

none- Автор вопроса
Ghasem Ramezani
malloc(3) gives you a void* , you must specify the...

int* ptr = (int *) malloc(4) doesn't make sense why ptr has to be declared as int* twice here

none
int* ptr = (int *) malloc(4) doesn't make sense wh...

This is two operations smooshed together int* ptr; ptr = (int*) malloc(sizeof(i)); Bear in mind that malloc returns void*

none- Автор вопроса
Nader Jafari
This is two operations smooshed together int* ptr;...

Okay, so this is how it's done what about the Realloc ques?

yes

none- Автор вопроса
Peco
yes

So that means push_back() of vector in cpp (which is also a dynamic array) has no time complexity compared to realloc?

none
So that means push_back() of vector in cpp (which ...

A vector, holds a array. It's dynamic, but this dynamic comes into play when the array is filled up, so it expands the array, using malloc/realloc and copies old data to new array. When you do push_back(), if array is not full, it will be o(1) but if it's full it would be o(1)+o(time to reallocate n*existing array size and copy data)

none- Автор вопроса
The prodigal ᥀
A vector, holds a array. It's dynamic, but this dy...

thanks for taking out time to type that much I understand now ah

No, in C you have autocast from void*. Realloc enlarge Memory allocated, but if can't 1)create new Memory 2)Copy to new address O(n) 3)release old address.

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта