Похожие чаты

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

14 просмотров

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- Автор вопроса
Yamikani ᥀
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.

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

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

Здравствуйте! Есть вопросы по ПК: 1.1. Безопасно ли запускать программы, которым я не доверяю, в виртуальной машине под KVM+qemu? (x86_64) 1.2. То же самое при использовании ...
Pavel
5
Hi everyone! I have a two-folded message to share today. First: updates and news, as we are being asked for those. We still want to go like we did the last 6 years: we w...
Marten | Unibright.io
31
Я тут пытаюсь переработать архитектуру подсистемы памяти ядра во что-то осмысленное. Есть pmm, который создает набор range’ей(пока что только для ядра, потом для юзерспейса), ...
Evg Resh
9
Комрады, хотел уточнить. Проперть в OnDestroy юнита-хозяина по-прежнему доступна? И еще уточнение: finalization юнита наступает раньше или позже OnDestroy?
Ed Doc
21
У меня вопрос, а какой уровень оптимизации ставить при сборке на i5 4 ядра 16G ddr3 ОЗУ и видюха Geforce GTX 970?
Sir Jiga
18
Guys, what’s the most expensive part of your budget for your business/startup/app/website?
Ice Kream
18
Скажите, можно ли как-то "переместить" динамический массив из одной переменной в другую? Скажем, переместить из TList<> в TArray<>. Именно переместить, а не скопировать. Если ...
Eugene Krasnikov (ᴊɪɴ x)
37
Oh.... Admins at the main TG is already muted me. How many months Sir you muted me? Or forever if you are here @Janevietani @JohnnySonic
Charles Dar
28
Happy Friday and happy CartesiWeekly! This week on the list: 🪲 Bug Buster Update 🎥 Erick de Moura’s interview with Ornella from Web3TV 👽 Thriving Cartesi alien 🇧🇷 SBRC hackat...
Nida | Cartesi - Never DM first or ask for funds!
1
комрады, че-та лыжы не едут var tmpFont: TFont; begin tmpFont:= TFont.Create; try case rgFontColor.ItemIndex of 0: tmpFont.Color:= clWindowText; 1: tmpFo...
Ed Doc
34
Карта сайта