Sometimes C++ can be a PITA
-
I'm probably old fashioned, but I don't find C++ that helpful when it comes to embedded work - stick to C and assembler is my preferred route. The idea of embedded is to get the best performance out of limited resources (speed, memory and / or power) and the extra overhead of class based OOPs isn't necessarily a good idea. And it's way harder to keep an eye on memory management to ensure memory fragmentation doesn't rear its ugly head after 2 weeks of continual runtime ... :laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
OriginalGriff wrote:
I don't find C++ that helpful when it comes to embedded work
I disagree c++, I've used C++ on various platforms for years and never had a problem. I find; code size comparable, speed acceptable (you can also mix c++ and assembler). The Arduino platform uses c++ as it's major language and there are libraries for everything under the sun.
A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator
-
Working with an STM32 device and trying to implement program in c++. Every platform is a little different in the way it implements C++ so trying to learn the ins and outs on the STM32. Been working on a simple Timer singleton class for the past 6 hours and it's been 2 steps forward and 1 back. Should be fairly easy but there were so many gotchas that made it very frustrating.
A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator
I use the C runtimes with C++ language features on embedded. I avoid the STL and most of the C++ standard runtimes. Why? For the exact reasons you're running into - the C runtimes in general are far more consistent platform to platform. Furthermore, The STL is not set up to use the heap responsibly on constrained systems. You will get heap frag and eventual crashes without creating your own custom allocators for everything.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
I'm probably old fashioned, but I don't find C++ that helpful when it comes to embedded work - stick to C and assembler is my preferred route. The idea of embedded is to get the best performance out of limited resources (speed, memory and / or power) and the extra overhead of class based OOPs isn't necessarily a good idea. And it's way harder to keep an eye on memory management to ensure memory fragmentation doesn't rear its ugly head after 2 weeks of continual runtime ... :laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
Forget classes. template and constexpr mean I can create faster/more efficient code in C++ than you can readily create in C. You don't have to use features that generate overhead in C++. Zero overhead C++ is a thing. Besides, Generic Programming > Object Oriented Programming anyway
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
I use the C runtimes with C++ language features on embedded. I avoid the STL and most of the C++ standard runtimes. Why? For the exact reasons you're running into - the C runtimes in general are far more consistent platform to platform. Furthermore, The STL is not set up to use the heap responsibly on constrained systems. You will get heap frag and eventual crashes without creating your own custom allocators for everything.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
honey the codewitch wrote:
I avoid the STL and most of the C++ standard runtimes.
Ditto I ran into problems because of basic stupidity on my part and trying to do something that I hadn't done before. Responsible memory/resource management is crucial in all embedded languages. I generally don't do dynamic memory allocation, just instantiate classes once. When I do need to do dynamic memory allocation I attempt to allocate blocks that are the same size to reduce fragmentation. When I can't do that I am very cautious to destroy when done with. You can shoot just as big a hole in your foot using C as C++!
A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator
-
honey the codewitch wrote:
I avoid the STL and most of the C++ standard runtimes.
Ditto I ran into problems because of basic stupidity on my part and trying to do something that I hadn't done before. Responsible memory/resource management is crucial in all embedded languages. I generally don't do dynamic memory allocation, just instantiate classes once. When I do need to do dynamic memory allocation I attempt to allocate blocks that are the same size to reduce fragmentation. When I can't do that I am very cautious to destroy when done with. You can shoot just as big a hole in your foot using C as C++!
A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator
I guess I misunderstood some of your initial comment. I am not fully coffee'd yet. :-\
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
I'm probably old fashioned, but I don't find C++ that helpful when it comes to embedded work - stick to C and assembler is my preferred route. The idea of embedded is to get the best performance out of limited resources (speed, memory and / or power) and the extra overhead of class based OOPs isn't necessarily a good idea. And it's way harder to keep an eye on memory management to ensure memory fragmentation doesn't rear its ugly head after 2 weeks of continual runtime ... :laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
Working with an STM32 device and trying to implement program in c++. Every platform is a little different in the way it implements C++ so trying to learn the ins and outs on the STM32. Been working on a simple Timer singleton class for the past 6 hours and it's been 2 steps forward and 1 back. Should be fairly easy but there were so many gotchas that made it very frustrating.
A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator
watch out for memory allocation. Project I was on 5+ years ago was burned with "new" and other items for memory allocation not being thread safe. There was a macro to define that fixed everything.
Charlie Gilley “Microsoft is the virus..." "the problem with socialism is that eventually you run out of other people's money"
-
Sounds painful, but also like article material.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
Comments reflect a mix of humor and truth. The debugging experience can be frustrating, much like navigating the slope game tricky slopes. Social media often blurs reality; as the quote suggests, on Facebook, we're more likely to embellish, while Twitter showcases our raw feelings.
-
Forget classes. template and constexpr mean I can create faster/more efficient code in C++ than you can readily create in C. You don't have to use features that generate overhead in C++. Zero overhead C++ is a thing. Besides, Generic Programming > Object Oriented Programming anyway
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
honey the codewitch wrote:
classes. template
Aren't these almost equivalent, at some point ? Thinking in this way : https://stackoverflow.com/questions/879535/what-is-the-difference-between-a-template-class-and-a-class-template[^]
-
honey the codewitch wrote:
classes. template
Aren't these almost equivalent, at some point ? Thinking in this way : https://stackoverflow.com/questions/879535/what-is-the-difference-between-a-template-class-and-a-class-template[^]
Nah. template can be applied to functions as well as struct/class. Warning - basic implementation details: When your compiler sees a template instantiation it basically works like a mail merge for source code, but with typed inputs. It takes those inputs, and uses the template to determine what TEXTUAL output to produce. That C++ text output is then fed back to the compiler and fully parsed/compiled (some initial parsing is done on the preinstantiated template, but it's not fully processed by the compiler until instantiation). That's the functionality of the template keyword. It's a source code generator. Edit: I should add, with template you often create "throw away" types - they're never actually used at runtime, and the compiler generates no direct machine code output for them. I don't consider those to be actual structs/classes because they are never used. They are simply a way to cajole the compiler into doing things it wasn't designed for when C++ was dreamed up.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
Sounds painful, but also like article material.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
Internet vạn vật (IoT): Viễn thông đang thúc đẩy các thành phố thông minh như thế nào
khoảng 22 giờ trước
bởi Liam Smith
Khi các thành phố trở nên thông minh hơn, cơ sở hạ tầng viễn thông đang đóng vai trò quan trọng trong việc tạo điều kiện cho Internet vạn vật (IoT). Từ đèn giao thông thông minh đến hệ thống quản lý chất thải, các thiết bị IoT đều dựa vào kết nối internet mạnh mẽ, nhanh và độ trễ thấp để hoạt động liền mạch. Các công ty viễn thông đang đầu tư mạnh vào việc xây dựng cơ sở hạ tầng cần thiết để hỗ trợ các thiết bị này, sử dụng kết hợp 5G, cáp quang và điện toán biên để đảm bảo dữ liệu có thể được xử lý theo thời gian thực. Ví dụ, ô tô được kết nối dựa vào mạng nhanh để giao tiếp với nhau và với hệ thống giao thông để ngăn ngừa tai nạn và tối ưu hóa lưu lượng giao thông. Tương tự như vậy, các tòa nhà thông minh sử dụng cảm biến IoT để quản lý mức tiêu thụ năng lượng hiệu quả hơn. Sự gia tăng của các thành phố thông minh do IoT thúc đẩy có thể cải thiện đáng kể cuộc sống đô thị, giảm tắc nghẽn, cải thiện an toàn và giảm tác động đến môi trường. Khi số lượng thiết bị được kết nối tiếp tục tăng, vai trò của các công ty viễn thông trong việc thúc đẩy tương lai này sẽ ngày càng trở nên quan trọng hơn.