● Igor
when the cost of virtual functions is considerable to not use it?
/
Hi i need help
/
how i read from a big endian file
/
integers
Hussein
how i read from a big endian file
use functions from <endian.h>
Hussein
wait i try
read 4 bytes then use the function
/
read 4 bytes then use the function
but there isnt any endian.h
Hussein
What is the function
#include <endian.h> uint16_t htobe16(uint16_t host_16bits); uint16_t htole16(uint16_t host_16bits); uint16_t be16toh(uint16_t big_endian_16bits); uint16_t le16toh(uint16_t little_endian_16bits); uint32_t htobe32(uint32_t host_32bits); uint32_t htole32(uint32_t host_32bits); uint32_t be32toh(uint32_t big_endian_32bits); uint32_t le32toh(uint32_t little_endian_32bits); uint64_t htobe64(uint64_t host_64bits); uint64_t htole64(uint64_t host_64bits); uint64_t be64toh(uint64_t big_endian_64bits); uint64_t le64toh(uint64_t little_endian_64bits);
Hussein
What is the function
you may need to use be64toh()
Pavel
when the cost of virtual functions is considerable to not use it?
This is not an easy question. I would say when you can avoid it without making the code more complex. One example would be if you have an array of pointers with many objects (how many? Not sure, I would say 100k+) of objects of different types that are mixed together (not sorted by type), and you need to iterate over them often. Problem here is that if you call different versions of the virtual function, their instructions will less likely be ready in the CPU cache when they're needed, resulting in increased cache misses. However, if you sort the objects by type in your container you could improve the situation.
/
you may need to use be64toh()
i understanded but the library
/
you may need to use be64toh()
the library doesnt exist
Hussein
the library doesnt exist
what OS are you using?
Hussein
windows
explains a lot
Hussein
why
it is the only one that doesn’t support it
Hussein
why not
it is a really good question to ask bill gates
Hussein
why not
you can flip the bits yourself but first let me check if windows provide a solution
Hussein
yes
#include <byteswap.h> does this work?
Hussein
it doesnt exist too
how about <intrin.h>
/
how i use it
Hussein
for 16 bits unsigned short _byteswap_ushort(unsigned short value); For 32 bit numbers: unsigned long _byteswap_ulong(unsigned long value); For 64 bit numbers: unsigned __int64 _byteswap_uint64
Hussein
thank yoi
for 64 bits: unsigned __int64 _byteswap_uint64(unsigned __int64 value);
/
for 64 bits: unsigned __int64 _byteswap_uint64(unsigned __int64 value);
do you know why this doesnt work ifstream file ( name, ios :: binary );
/
it tells me incomplete type not allowed
/
and local variable not initialized
Hussein
thank yoi
you can also use <netinet/in.h> for 32bits integers to convert big to little endian: uint32_t ntohl(uint32_t netlong); and from little to big you can use: uint32_t htonl(uint32_t hostlong);
Hussein
do you know why this doesnt work ifstream file ( name, ios :: binary );
sorry I don’t code in C++ but this works the same in C and C++
Hussein
but do you also know why that thing doesnt work
each operating system provide libraries for developers some operating systems makers deside to stick to some standards like Unix and POSIX so they implement functions specified by these standards but windows and even DOS desided not to follow many standards that make development cross-platform and make our lives easier
Hussein
but do you also know why that thing doesnt work
almost all websites on the web focus on linux and unix(including BSD and macos) in C tutorials and forums which tries to stick to those standards as much as possible
Michel
Is std::async an implementation of asynchronous programming similar to Python asyncio or multithreading? I'm trying to learn a bit of that and it's been two videos that tell srd::async creates a thread.
pavel
It's not their main advantage
pavel
Formally standard don't say will it create a thread or not. Standard say it will create a future object that handle a tasks run in different thread that call thread
Linuxx
Okay
Linuxx
I need c++ set up on Mac
Anonymous
Is std::async an implementation of asynchronous programming similar to Python asyncio or multithreading? I'm trying to learn a bit of that and it's been two videos that tell srd::async creates a thread.
It depends on the launch policy. If launch policy is async, it tries to spawn a new thread. If the launch policy is deferred, then a new thread is not spawned and lazy evaluation is done in the context of the thread where async was called Also keep in mind that the return value of the async call can determine if you have parallelism. If you ignore the return value of async i.e. the future that is returned, then the destructor of this temporary will block and what you will get is something similar to sequential execution (even if you used launch policy async, the main thread will be essentially blocked) where one thread waits for the async thread to complete before it proceeds.
Anonymous
I need c++ set up on Mac
Just search for IDE in that channel.
Alireza
How can I access Resource File in C++ ?
Alireza
Should I use win32?
Alireza
plz help:)
mito
When you have something like BYTE some_value = {0x32, 0xC, 0x0, 0x0} How is this byte read here in int ? Is this little or big endian? #cpp
Hussein
When you have something like BYTE some_value = {0x32, 0xC, 0x0, 0x0} How is this byte read here in int ? Is this little or big endian? #cpp
what is your cpu? if you are using intel CPUs, which is the case on almost all laptops and personal computers (except raspbery pi and the new mac) then your integers are little endian if you are using arm or mips I have no idea and I cannot be sure because it is left to the compiler and programs😅 if you are using powerpc then you are using big endian
Hussein
it's AMD, so most likely little endian.
why do u care about the endianness?
mito
why do u care about the endianness?
Because, I want to know how to convert it into int.
Hussein
Because, I want to know how to convert it into int.
use ntohs() to convert to network endian (big endian), and htons() to convert from your endianness (whatever is your endianess) to the network endianess
Hussein
Hussein
Because, I want to know how to convert it into int.
use the functions above if you use linux but netinet is more cross-platform
mito
When you have something like BYTE some_value = {0x32, 0xC, 0x0, 0x0} How is this byte read here in int ? Is this little or big endian? #cpp
I wanted to say beforehand that by BYTE I meant unsigned char. Like typedef unsigned char BYTE;
Hussein
Because, I want to know how to convert it into int.
btw h stand for host l stand for long s stand for short le stand for little endian be stand for big endian for 32bit integers use htonl() and ntohl()
Hussein
only integers
mito
yeah, I forgor
Ruslan
Hi! I found that I don't have libsupc++ installed. How can I install libsupc++ ?
Ruslan
what os ur using?
It is a custom Linux image built with Yocto Project
Hussein
It is a custom Linux image built with Yocto Project
check your package manager repos if it is available otherwise you have to compile it from scratch
پشتیبان
hi I want to start learning c++, Does anyone have a roadmap?
پشتیبان
which resources do you suggest to me?
Anonymous
Hii everyone, myself Neha.. I'm a student and I've recently been intresting in coding nd programming.. I'm new to all this so i hope u all can help me with that :)
Anonymous
For instance I'm not able to differentiate btw struct nd class??