Похожие чаты

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 ответов

26 просмотров

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.

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

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

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
15
Hi guys, any problem with Pulsebrige? Trying to transfer from wETH to ETH. First it tells me to connect my metamask "through mobile app" not desktop. Then I did and confirmed ...
Snowflakecrypto
13
any reference of this implementation?
BitBuddha
29
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
&"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64\dumpbin.exe" /EXPORTS C:\Users\Yeet\Tauon\vcpkg\installed\x64-window...
Martin Rys
6
Карта сайта