OOC与CPP生成代码大小对比
今天做了一个简单的对比测试,看一下gcc模拟oo与g++生成代码(strip无用符号后)大小的比较
下面附上测试demo,先来OOC的
/* * test_Animals.c * * Created on: 2011-5-16 * Author: Jesse Meng [pingf0@gmail.com] */ #include "OOStd.h" CLASS(Animal){ char *name; STATIC(Animal) vFn talk; }; int Animal_reload(Animal *THIS,char *name){ THIS->name=ALLOC(strlen(name)+1); memcpy(THIS->name,name,strlen(name)); return 0; } int Animal_unload(Animal *THIS,void *PARAM){ FREE(THIS->name); return 0; } ASM(Animal,Animal_reload,Animal_unload,NULL,NULL) CLASS_EX(Animal,Cat){ STATIC_EX(Animal,Cat) }; static void Meow(Animal *THIS){ printf("Meow!My name is %s!\n",THIS->name); } int Cat_reloadSt(StAnimal *THIS,void *PARAM){ THIS->talk=(void *)Meow; return 0; } ASM_EX(Animal,Cat,NULL,NULL,Cat_reloadSt,NULL) CLASS_EX(Animal,Dog){ STATIC_EX(Animal,Dog) }; static void Woof(Animal *THIS){ printf("Woof!My name is %s!\n",THIS->name); } int Dog_reloadSt(StAnimal *THIS,void *PARAM){ THIS->talk=(void *)Woof; return 0; } ASM_EX(Animal,Dog,NULL,NULL,Dog_reloadSt,NULL) int main(){ Animal *a[]={ /////////////////////////// (void*)newDog("Jack"), (void *)newCat("Lily"), (void*)newDog("Mike"), (void *)newCat("Lucy"), // 100个,这里懒得写了,因为测试时是cccv的 ..... }; int i=0; //StAnimal *f=ST((Dog*)(a[0])); StAnimal *f=ST((Dog*)(a[0])); for(i=0;i<100;++i){ f->talk(a[i]); } for(i=0;i<100;++i){ //delDog((Dog**)&(a[i]),NULL); delDog((Dog**)&(a[i]),NULL); } return 0; }
下面来看下CPP的
#include <iostream> #include <string> using namespace std; class Animal { public: Animal(const string& name) : name(name) {} virtual void talk() = 0; const string name; }; class Cat : public Animal { public: Cat(const string& name) : Animal(name) {} virtual void talk() { cout<<"Meow!Myname is "+name<<endl; } }; class Dog : public Animal { public: Dog(const string& name) : Animal(name) {} virtual void talk() { cout<<"Woof!Myname is "+name<<endl; } }; int main() { Animal* animals[] = { /////////////// new Dog("Jack"), new Dog("Mike"), new Cat("Lily"), new Cat("Lucy"), // 这里同样100个 ..... }; for(int i = 0; i < 100; i++){ animals[i]->talk(); } for(int i = 0; i < 100; i++){ delete animals[i]; } return 0; }
尽管我已经将OOC-GCC写的足够简单了,但还是比CPP写出来稍长一点(感觉还好一般20行左右)
不过编译出来的我还是比较满意的,
上面两段代码输出一致,风格一致,都是最基本的形式.
类设计为一个基类,两个近似的继承类,100个任意继承类的对象.
先生成100堆对象,执行100次各对象的基本方法,然后逐一销毁.
实际测试后cpp编译出来的体积为32246,通过OOC-GCC宏出来仅为21518(而这里面还包括内存分配日志,时间测试等函数的调用)
这个多少有点出乎我的意料,因为OOC-GCC通过宏引入了相当多的辅助函数,比如上面的实际用到的关于对象辅助生成的函数应该至少有24个,而且每个体积也不小的.
Fri, 10 Nov 2017 20:30:33 -1100
If any page has quality posts like yours then I will search for information very quickly. Please donate again
Sun, 26 Nov 2017 16:16:13 -1100
c/c++视频教程
http://www.sucaihuo.com/video/197-0-0
Wed, 28 Sep 2022 06:02:31 -1100
Generally the Sanskrit sample papers are prepared by the subject experts of Leading Educational Institutes for all 11th standard students with all important questions. In fact, NCERT Sanskrit Question Paper Class 11 the questions that are given in Sanskrit model papers are taken from the 11th Standard Sanskrit studying syllabus which is mentioned in NCERT Sanskrit sample papers 2023 class 11.Generally the Sanskrit sample papers are prepared by the subject experts of Leading Educational Institutes for all 11th standard students with all important questions. In fact.
Mon, 18 Dec 2023 19:05:23 -1100
Regards for this post, I am a big fan of this website would like to go along updated. 攝影器材
===============================
I am often to blogging and i really appreciate your content. The article has really peaks my interest. I am going to bookmark your site and keep checking for new information. 腳架
Thu, 21 Dec 2023 05:17:59 -1100
You really should experience a tournament for starters of the finest blogs online. Let me recommend this great site! collagen tablets
===============================
Hey! Good stuff, please keep us posted when you post something like that! collagen powder
==============================
I thought it was going to be some boring old publish, but it really compensated for my time. I will publish a link to this page on my blog. I am confident my visitors will discover that quite useful Orange County Sub-Zero appliance repair
Thu, 21 Dec 2023 20:59:20 -1100
hey you should get social media plugin. was looking for the ‘like’ button but couldn’t find it. series torrent
===================
I’m impressed, I have to admit. Actually rarely will i encounter a weblog that’s both educative and entertaining, and let me tell you, you’ve got hit the nail within the head. Your idea is outstanding; the problem is an element that not enough everyone is speaking intelligently about. My business is very happy i always stumbled across this at my find some thing about it. Taller de coches en Aguo Miraballes
Sat, 23 Dec 2023 04:07:01 -1100
I’m impressed, I must say. Actually rarely can i encounter a blog that’s both educative and entertaining, and let me tell you, you could have hit the nail to the head. Your concept is outstanding; the thing is an issue that inadequate consumers are speaking intelligently about. We’re very happy which i came across this inside my search for something concerning this. NANOFILTRATION ULTRAFILTRATION SYSTEMS MANUFACTURER NF UF MF FILTRATIONS SYSTEMS FOR WATER FILTRATION
Mon, 25 Dec 2023 05:44:10 -1100
I believe this web site has some rattling wonderful info for everyone . DESALINATION PLANT MANUFACTURER
Thu, 07 Mar 2024 05:07:16 -1100
: Effortless Cannabis Convenience: The Ultimate Guide to Weed Delivery
In the rapidly evolving world of cannabis, Weed Delivery emerges as a game-changer, providing unparalleled convenience for enthusiasts. With a few clicks, users can access a plethora of strains and products right at their doorstep.
Seamless Ordering: Explore a user-friendly interface that simplifies the Weed Delivery process, ensuring a hassle-free experience.
Extensive Product Range: Choose from a diverse selection of top-notch strains, edibles, and accessories, catering to every preference.
Swift and Discreet Delivery: Enjoy prompt and discreet service, prioritizing your privacy and ensuring a seamless transaction.
Quality Assurance: Rest easy with premium products, rigorously tested to meet the highest industry standards.
Exclusive Deals and Discounts: Benefit from exciting promotions and loyalty programs, enhancing the value of your Weed Delivery experience.
Embrace the future of cannabis accessibility with our comprehensive guide to Weed Delivery services. Your journey to premium, hassle-free cannabis enjoyment starts here!
Sun, 08 Dec 2024 04:08:00 -1100
Hello! I just wanted to ask if you ever have any issues with hackers? My last blog (wordpress) was hacked and I ended up losing several weeks of hard work due to no back up. Do you have any methods to stop hackers? ECサイト セキュリティ
Sun, 08 Dec 2024 04:08:15 -1100
You produced some decent points there. I looked online for your problem and located most people will go together with with the website. EC-CUBE カスタマイズ