Lines Matching full:n
35 // perl -CIO -ne '$_ =~ s/([^\n -~])/"\\u" . sprintf("%04x", ord($1))/ge; print $_;' < unicode-test…
40 "中国历史\n" +
41 "[编辑首段]维基百科,自由的百科全书\n" +
42 "跳转到: 导航, 搜索\n" +
43 "中國歷史\n" +
44 "中国历史系列条目\n" +
45 "史前时期\n" +
46 "传说时期\n" +
47 "(另见三皇五帝)\n" +
48 "夏\n" +
49 "商\n" +
50 "西周 周\n" +
51 "春秋 东周\n" +
52 "战国\n" +
53 "秦\n" +
54 "西汉 汉\n" +
55 "新朝\n" +
56 "东汉\n" +
57 "魏 蜀 吴 三\n" +
58 "国\n" +
59 "西晋 晋\n" +
60 "东晋 十六国\n" +
61 "宋 南\n" +
62 "朝 北魏 北\n" +
63 "朝 南\n" +
64 "北\n" +
65 "朝\n" +
66 "齐\n" +
67 "梁 东\n" +
68 "魏 西\n" +
69 "魏\n" +
70 "陈 北\n" +
71 "齐 北\n" +
72 "周\n" +
73 "隋\n" +
74 "唐\n" +
75 "(另见武周)\n" +
76 "五代十国\n" +
77 "辽\n" +
78 "(西辽) 西\n" +
79 "夏 北宋 宋\n" +
80 "金 南宋\n" +
81 "元\n" +
82 "明\n" +
83 "清\n" +
84 "中华民国\n" +
85 "中华人民\n" +
86 "共和国 中华\n" +
87 "民国\n" +
88 "(见台湾问题)\n" +
89 "\n" +
90 " * 中国历史年表\n" +
91 " * 中国军事史\n" +
92 " * 中国美术史\n" +
93 " * 中国科学技术史\n" +
94 " * 中国教育史\n" +
95 "\n" +
96 "中国\n" +
97 "天坛\n" +
98 "文化\n" +
99 "中文 - 文学 - 哲学 - 教育\n" +
100 "艺术 - 国画 - 戏曲 - 音乐\n" +
101 "神话 - 宗教 - 术数 - 建筑\n" +
102 "文物 - 电影 - 服饰 - 饮食\n" +
103 "武术 - 书法 - 节日 - 姓名\n" +
104 "地理\n" +
105 "疆域 - 行政区划 - 城市\n" +
106 "地图 - 旅游 - 环境 - 生物\n" +
107 "人口 - 民族 - 交通 - 时区\n" +
108 "历史\n" +
109 "年表 - 传说时代 - 朝代\n" +
110 "民国史 - 共和国史\n" +
111 "文化史 - 科技史 - 教育史\n" +
112 "人口史 - 经济史 - 政治史\n" +
113 "政治\n" +
114 "中华人民共和国政治 - 中华民国政治\n" +
115 "宪法 - 外交 - 军事 - 国旗\n" +
116 "两岸问题 - 两岸关系\n" +
117 "一个中国 - 中国统一\n" +
118 "经济\n" +
119 "金融 - 农业 - 工业 - 商业\n" +
120 "中国各省经济 - 五年计划\n" +
121 "其他\n" +
122 "列表 - 体育 - 人权 - 媒体\n" +
123 "\n" +
124 …年前(公元前1600年)商朝的甲骨文、约4000年前至7000年前的陶文、约7000年前至10000年前具有文字性貭的龟骨契刻符号。另外,目前在中国发现最早的史前人类遗址距今约200万年。\n" +
125 "\n" +
126 …政治,汉朝起则以文官主治国家直至清朝,清末以降,民主政治、马克思主义等各种政治思潮流传,先促成中华民国的建立,并于其后四、五十年再出现中华人民共和国,而由于内战失败,中华民国政府退守台湾。\n" +
127 "\n" +
128 …80年代以来工业化发展迅猛,数亿人口在短短20多年内从农民转为产业工人(目前仅仅被称为“农民工”的产业工人就达到约2亿)。伴随经济的迅速国际化,中国经济成为全球经济中越来越重要的组成部分。\n" +
129 "目录\n" +
130 "[隐藏]\n" +
131 "\n" +
132 " * 1 史前时代\n" +
133 " * 2 传说时代\n" +
134 " * 3 先秦时期\n" +
135 " o 3.1 三代\n" +
136 " o 3.2 春秋战国\n" +
137 " * 4 秦汉时期\n" +
138 " * 5 魏晋南北朝时期\n" +
139 " * 6 隋唐五代时期\n" +
140 " * 7 宋元时期\n" +
141 " * 8 明清时期\n" +
142 " o 8.1 清末的内忧外患\n" +
143 " * 9 20世纪至今\n" +
144 " * 10 参见\n" +
145 " * 11 其他特定主题中国史\n" +
146 " * 12 注解\n" +
147 " * 13 参考文献\n" +
148 " * 14 相关著作\n" +
149 " * 15 外部链接\n" +
150 "\n" +
151 "[编辑] 史前时代\n" +
152 "大汶口文化的陶鬹,山東莒县大朱村出土\n" +
153 "大汶口文化的陶鬹,山东莒县大朱村出土\n" +
154 "\n" +
155 …00万年前生活在中国江南一带。考古证据显示224万年至25万年前,中国就有直立人居住,目前考古发现的有巫山人、元谋人、蓝田人、南京直立人、北京直立人等。这些都是目前所知较早的原始人类踪迹。\n" +
156 "\n" +
157 "中国史前时代的各种文化是经过了以下几个阶段:以直立猿\n" +
158 …在20至10余万年前。新石器时代早期的代表性文化是裴李岗文化,紧接着是以仰韶文化为代表的新石器时代中期。而以龙山文化为代表的新石器时代晚期,大约出现在公元前2500年到公元前1300年间。\n" +
159 "\n" +
160 …的仰韶文化便具备使用红陶、彩陶以及食用粟和畜养家畜的特质。而大约在同一时间,尚有在浙江省北边出现的河姆渡文化、山东省的大汶口文化。而之后发现的如二里头遗址和三星堆遗址则为青铜器时代的代表。\n" +
161 "\n" +
162 "[编辑] 传说时代\n" +
163 "\n" +
164 " 主条目:三皇五帝\n" +
165 "\n" +
166 "後人所繪的黄帝像\n" +
167 "后人所绘的黄帝像\n" +
168 "\n" +
169 …夏朝以前数千年杰出首领的代表,具体而言有不同的说法。一般认为,三皇是燧人、伏羲、神农以及女娲、祝融中的三人,五帝一般指黄帝、颛顼、帝喾、尧、舜。自三皇至五帝,历年无确数,最少当不下数千年。\n" +
170 "\n" +
171 "据现今整理出来的传说,黄帝原系炎帝部落的一个分支的首领,强大之后在阪泉之战中击败炎帝,成为新部落联盟首领,之后又与东南方的蚩尤部落发生冲突,在涿鹿之战中彻底击败对手,树立了自己的霸主地位。\n" +
172 "\n" +
173 …自立为王(但据《史记》及香港中学课本所述,启是被推举为领袖),建立了第一个世袭王朝——夏朝,夏朝持续了400多年,在最后一个夏朝君主——桀末期,东方诸侯国商首领成汤夺取了政权,建立了商朝。\n" +
174 "\n" +
175 "[编辑] 先秦时期\n" +
176 "\n" +
177 "[编辑] 三代\n" +
178 "\n" +
179 " 主条目:夏朝、商朝、周朝和西周\n" +
180 "\n" +
181 "甲骨文\n" +
182 "甲骨文\n" +
183 "\n" +
184 …业,不过手工业,特别是青铜器的冶铸水平也已经十分高超。并且已经出现了原始的瓷器。商朝自盘庚之后,定都于殷(今河南安阳),因此也称为殷朝。商朝的王位继承制度是传子或传弟,多按年龄的长幼继承。\n" +
185 "\n" +
186 …,西至甘肃,东到山东。周朝时的宗法制度已经建立,政权机构也较完善。自唐尧、虞舜至周朝皆封建时代,帝王与诸侯分而治之[1]。中国最早有确切时间的历史事件是发生于公元前841年西周的国人暴动。\n" +
187 "\n" +
188 "[编辑] 春秋战国\n" +
189 "\n" +
190 " 主条目:周朝、东周、春秋时期和战国 (中国)\n" +
191 "\n" +
192 "先師孔子行教像,為唐朝画家吳道子所画\n" +
193 "先师孔子行教像,为唐朝画家吴道子所画\n" +
194 "\n" +
195 …划为封建社会,然而大部分西方及台湾学者却又将之划为封建社会的崩溃。前356年秦国商鞅变法开始后,秦国国力大大增强,最后终于在前221年消灭六国最后的齐国,完成统一,中国历史也进入了新时代。\n" +
196 "\n" +
197 …分发达,能制造精良的铁器,在农业上出现了各种灌溉机械,大大提高了生产率,从而为以后人口大大膨胀奠定了基础。历史上出现了春秋(左传),国语,战国策。中华文化的源头基本上都可以在这一时期找到。\n" +
198 "\n" +
199 "这一时期科技方面也取得了很大进步。夏朝发明了干支纪年,出现了十进位制。西周人用圭表测日影来确定季节;春秋时期确定了二十八宿;后期则产生了古四分历。\n" +
200 "\n" +
201 "[编辑] 秦汉时期\n" +
202 "\n" +
203 " 主条目:秦朝、汉朝、西汉、新朝和东汉\n" +
204 "\n" +
205 "北京八達嶺長城\n" +
206 "北京八达岭长城\n" +
207 "\n" +
208 …,收缴天下兵器,役使七十万人修筑阿房宫以及自己的陵墓——包括兵马俑等。部分史学家对以上事件存有怀疑,认为由于秦始皇的一系列激进改革得罪了贵族,平民无法适应,才在史书上留此一笔。[来源请求]\n" +
209 "\n" +
210 …交流。儒家学说也被确立为官方的主流意识形态,成为了占统治地位的思想。其他艺术与文化也蒸蒸日上。同时期还出现了第一部通史性质的巨著——《史记》,同时这时的中国出现造纸术,大大推动了文化发展。\n" +
211 "\n" +
212 …武帝。东汉的发展延续了西汉的传统,此时出现了天文学家张衡。汉的文化吸取了秦的教训,显得相当开明,当时佛教通过西域到达中国,在河南洛阳修建了中国的第一座佛教寺庙——白马寺,佛教正式传入中国。\n" +
213 "\n" +
214 "[编辑] 魏晋南北朝时期\n" +
215 "\n" +
216 " 主条目:魏晋南北朝、三国、晋朝、十六国和南北朝\n" +
217 "\n" +
218 "赤壁\n" +
219 "赤壁\n" +
220 "\n" +
221 …二世纪左右时再度衰败,196年曹操控制了东汉朝廷,把汉献帝迎至许都,“挟天子以令诸侯”,220年,曹操死后,长子曹丕废汉献帝自立,建立魏国,同时尚有刘氏的汉和孙氏的吴,历史进入了三国时期。\n" +
222 "\n" +
223 …族纷纷建立自己的国家,从304年到409年,北部中国陆陆续续有多个国家建立,包括了汉、前赵、后赵、前燕、前凉、前秦、后秦、后燕、西秦、后凉、北凉、南凉、南燕、西凉、夏和北燕, 史称十六国。\n" +
224 "\n" +
225 …—北魏,形成了南北朝的对立。南朝经历了宋、齐、梁、陈的更替,而北朝则有北魏、东魏、西魏、北齐和北周。南北朝时期是佛教十分盛行的时期,西方的佛教大师络绎不绝地来到中国,许多佛经被翻译成汉文。\n" +
226 "\n" +
227 "[编辑] 隋唐五代时期\n" +
228 "\n" +
229 " 主条目:隋朝、唐朝和五代十国\n" +
230 "\n" +
231 "唐代画家张萱作《捣练图》。\n" +
232 "唐代画家张萱作《捣练图》。\n" +
233 "\n" +
234 …周建立了隋朝,并于589年灭掉南朝最后一个政权——陈,中国历经了三百多年的分裂之后再度实现了统一。不过隋朝也是一个短命的王朝,在修筑了巨大工程——京杭大运河后就灭亡了,只经历了两代37年。\n" +
235 "\n" +
236 …、摩尼教(Manicheism)、景教和伊斯兰教等也得到了广泛传播。这一切都在李世民的曾孙唐玄宗李隆基统治时期达到顶峰,史称开元盛世。然而在755年,爆发了安史之乱,唐朝由此开始走向衰落。\n" +
237 "\n" +
238 "875年,黄巢起义爆发,唐朝再度分裂,并于907年灭亡,形成了五代十国的混乱局面。\n" +
239 "\n" +
240 "[编辑] 宋元时期\n" +
241 "\n" +
242 " 主条目:辽朝、金朝、西夏、宋朝和元朝\n" +
243 "\n" +
244 "清明上河圖局部,描繪了清明時節,北宋京城汴梁及汴河兩岸的繁華和熱鬧的景象和優美的自然風光。\n" +
245 "清明上河图局部,描绘了清明时节,北宋京城汴梁及汴河两岸的繁华和热闹的景象和优美的自然风光。\n" +
246 "\n" +
247 …中包括了当时的皇帝宋钦宗和太上皇宋徽宗,因为钦宗其时的年号为靖康,史称靖康之难,北宋灭亡。同年宋钦宗的弟弟赵构在南京应天府(今河南商丘)即皇位,定都临安(今浙江杭州),史称南宋,偏安江南。\n" +
248 "\n" +
249 …京)。元军于1279年与南宋进行了崖山海战,8岁的小皇帝赵昺被民族英雄陆秀夫背着以身殉国惨烈地跳海而死。崖山海战以元朝的胜利告终,南宋随之灭亡。另有一说, 原华夏文明至此夭折.[来源请求]\n" +
250 "\n" +
251 …倡三从四德。与唐诗并驾齐驱的宋词,有苏轼等词文优秀的词人,出现了中国历史上最著名的女词人李清照,社会文化发达,出现了白蛇传,梁祝等浪漫爱情传说,以至于宋朝被西方学者称为中国的“文艺复兴”。\n" +
252 "\n" +
253 …动多次反抗。元朝政府除了传统的农业外,也比较重视商业。元朝首都大都十分繁华,来自世界各国的商人云集。在文化上,则出现了与唐诗、宋词并称的元曲,涌现出诸如关汉卿、马致远、王实甫等著名作曲家。\n" +
254 "\n" +
255 "[编辑] 明清时期\n" +
256 "紫禁城太和殿\n" +
257 "紫禁城太和殿\n" +
258 "\n" +
259 " 主条目:明朝、南明、清朝和中国近代史\n" +
260 "\n" +
261 …1644年,起义首领李自成攻克北京,明思宗自缢。南方大臣先后拥护福王朱由崧(弘光)、唐王朱聿键(隆武)、桂王朱由榔(永历)为帝,史称南明,最终因实力不足及政治内斗,仍为当时强盛的清朝所灭。\n" +
262 "\n" +
263 …约》。清朝由于取消了丁税(人头税),导致人口增加,到19世纪已达当时世界总人口的三分之一,人口的增多促进当时农业的兴盛,为当时世界上第一强国,到1820年时中国的经济总量占世界的三分之一。\n" +
264 "\n" +
265 …皇帝不得不于1838年派林则徐赴广州禁烟。1839年6月,将237万多斤鸦片在虎门销毁,史称虎门销烟。英国政府因此于1840年6月发动鸦片战争。一般中国大陆史学界认为这是中国近代史的开始。\n" +
266 "\n" +
267 "[编辑] 清末的内忧外患\n" +
268 "一幅描繪列強瓜分中國情形的漫畫\n" +
269 "一幅描绘列强瓜分中国情形的漫画\n" +
270 "\n" +
271 …。香港岛被割让;上海、广州、厦门、福州和宁波开放作为通商口岸,还赔偿款银(西班牙银圆)2100万元。1844年,美国与法国也与清廷分别签订了《望厦条约》和《黄埔条约》,中国的主权受到破坏。\n" +
272 "\n" +
273 …占领南方部分省份,并定都南京(改名“天京”),建立政教合一的中央政权。同一时期其它的运动还有天地会、捻军、上海小刀会起义、甘肃回民起义等。这些反抗清朝的斗争直到1860年代才基本平息下来。\n" +
274 "\n" +
275 …库页岛(萨哈林岛)、海参崴(符拉迪沃斯托克)约40万平方公里的中国领土,划归俄国。1864年,《中俄勘分西北界约记》将巴尔喀什湖以东、以南和斋桑卓尔南北44万平方公里的中国领土,割给俄国。\n" +
276 "\n" +
277 …出的变法主张,从6月11日到9月21日的被称为百日维新的103天中进行了多项改革,但最终在慈禧太后发动政变后失败落幕,康有为、梁启超逃亡国外,谭嗣同、刘光第等六人被杀,史称“戊戌六君子”。\n" +
278 "\n" +
279 …国联军。1901年,清政府被迫与各国签定辛丑条约,赔款4.5亿两白银,分39年还清(本息合计9.8亿两),同时从北京到山海关铁路沿线由各国派兵驻扎,开北京东交民巷为使馆区,国人不得入内等。\n" +
280 "\n" +
281 "[编辑] 20世纪至今\n" +
282 "\n" +
283 " 主条目:中华民国历史和中华人民共和国史\n" +
284 "\n" +
285 …接任。但袁世凯妄图恢复帝制。此后,孙中山发起护法运动与护国运动讨伐袁世凯。1916年,袁世凯在称帝83天之后死去,中华民国进入北洋军阀控制中央政府统治时期,地方政府分别由各个军阀派系占据。\n" +
286 "\n" +
287 …贵州遵义确立了毛泽东对红军的领导和指挥权,四渡赤水河,终于摆脱了追击,途经江西,贵州,四川,甘肃,陕西,经过二万五千里长征,最后在陕西北部与陕北红军刘志丹部会师,建立陕甘宁共产党临时政府。\n" +
288 "毛泽東在天安门城楼上宣布中华人民共和國的成立\n" +
289 "毛泽东在天安门城楼上宣布中华人民共和国的成立\n" +
290 "\n" +
291 …民共和国在北平成立,并将北平改名为北京,毛泽东宣布中华人民共和国政府为包括台湾在内的全中国的唯一合法政府。与此同时,蒋介石宣布台北为中华民国临时首都,宣誓三年内反攻大陆。(请参看台湾问题)\n" +
292 "\n" +
293 …光养晦”的外交方针,在外交舞台上动作频繁,并加强对台湾的攻势。经济改革依然得到了持续,但政治改革的话题仍然是禁忌。而由于贫富差距的拉大与政治腐败不见好转,民间对中共的评价与看法也日益两极。\n" +
294 "\n" +
295 …进入了一个新的时代。之后,1996年实现了第一次民选总统;2000年更实现第一次政党和平轮替。2005年,末代国民大会召开,中华民国宪法出现了重大修改。今后,民主化的中华民国仍然充满变量。\n" +
296 "\n" +
297 "[编辑] 参见\n" +
298 "\n" +
299 " * 中国\n" +
300 " * 中国历史年表\n" +
301 " * 中国历史事件列表\n" +
302 " * 诸侯会盟\n" +
303 " * 中国历史地图\n" +
304 "\n" +
305 " \n" +
306 "\n" +
307 " * 中华人民共和国历史年表\n" +
308 " * 中华人民共和国史\n" +
309 " * 汉学\n" +
310 " * 中华文明\n" +
311 " * 中国历史大事年表\n" +
312 "\n" +
313 " \n" +
314 "\n" +
315 " * 中国文化\n" +
316 " * 中国行政区划\n" +
317 " * 中国朝代\n" +
318 " * 夏商周断代工程\n" +
319 " * 中国古都\n" +
320 "\n" +
321 " \n" +
322 "\n" +
323 " * 中国战争列表\n" +
324 " * 中国国旗\n" +
325 " * 中国皇帝\n" +
326 " * 中国历代王朝君主世系表\n" +
327 " * 中国君王诸子女列表\n" +
328 " * 中华民国历史\n" +
329 "\n" +
330 "[编辑] 其他特定主题中国史\n" +
331 "\n" +
332 " * 中国军事史\n" +
333 " * 中国科学技术史\n" +
334 " * 中国文化史\n" +
335 " * 中国文学史\n" +
336 " * 中国艺术史\n" +
337 " * 中国经济史\n" +
338 " * 中国体育史\n" +
339 " * 中国人口史\n" +
340 " * 中国疆域史\n" +
341 " * 中国盗墓史\n" +
342 " * 中国酷刑史\n" +
343 " * 中国食人史\n" +
344 " * 中国盐业史\n" +
345 "\n" +
346 "[编辑] 注解\n" +
347 "\n" +
348 " 1. ↑ 柳翼谋:《中国文化史》\n" +
349 "\n" +
350 "[编辑] 参考文献\n" +
351 "\n" +
352 " 1. 白寿彝主编:中国通史纲要,1993年上海:人民出版社,ISBN 7208001367\n" +
353 " 2. 周谷城著:中国通史,1995年上海:人民出版社,ISBN 7208003300\n" +
354 " 3. 李敖著:独白下的传统,2000年香港:三联书店(香港)有限公司,ISBN 9620418913\n" +
355 " 4. 范文澜著:中国近代史,1962年北京:人民出版社,统一书号 11001241\n" +
356 " 5. 徐中约著:中国近代史(上册),香港2001 中文大学出版社,ISBN 9622019870\n" +
357 …scow: URSS, 2006. ISBN 5-484-00559-0 [1] (Chapter 2: Historical Population Dynamics in China).\n" +
358 "\n" +
359 "[编辑] 相关著作\n" +
360 "\n" +
361 " * 《二十四史》 (正史)\n" +
362 " * 《国史要义》 柳诒徵\n" +
363 " * 《国史大纲》 钱穆\n" +
364 " * 《中华五千年史》 张其昀\n" +
365 "\n" +
366 "[编辑] 外部链接\n" +
367 "维基共享资源中相关的多媒体资源:\n" +
368 "中国历史\n" +
369 "\n" +
370 " * 中华万年网\n" +
371 " * 一个全面专门研究中华历史的论坛:中华历史网论坛\n" +
372 " * (正体中文 - 台湾)《中国大百科全书》:中国历史概述\n";
375 "История Китая\n" +
376 "[править]\n" +
377 "Материал из Википедии — свободной энциклопедии\n" +
378 "Перейти к: навигация, поиск\n" +
379 "История Китая\n" +
380 "История Китая\n" +
381 "Три властителя и пять императоров\n" +
382 "Династия Ся\n" +
383 "Династия Шан\n" +
384 "Династия Чжоу \n" +
385 "Западное Чжоу\n" +
386 "Восточное Чжоу Чуньцю\n" +
387 "Чжаньго\n" +
388 "Династия Цинь\n" +
389 "(Династия Чу) - смутное время\n" +
390 "Династия Хань Западная Хань\n" +
391 "Синь, Ван Ман\n" +
392 "Восточная Хань\n" +
393 "Эпоха Троецарствия Вэй Шу У\n" +
394 "Цзинь\n" +
395 " Западная Цзинь\n" +
396 "Шестнадцать варварских государств Восточная Цзинь\n" +
397 "Северные и Южные Династии\n" +
398 "Династия Суй\n" +
399 "Династия Тан\n" +
400 "Ляо\n" +
401 " \n" +
402 "5 династий и 10 царств\n" +
403 "Северная Сун\n" +
404 " \n" +
405 "Сун\n" +
406 "Цзинь\n" +
407 " \n" +
408 "Западная Ся\n" +
409 " \n" +
410 "Южная Сун\n" +
411 "Династия Юань\n" +
412 "Династия Мин\n" +
413 "Династия Цин\n" +
414 "Китайская республика\n" +
415 "Китайская Народная Республика\n" +
416 " Китайская республика (Тайвань)\n" +
417 "\n" +
418 …качестве государственной идеологии (I век до н. э.) и единой системы письма (II век до н. э.).\n" +
419 "Содержание\n" +
420 "[убрать]\n" +
421 "\n" +
422 " * 1 Древний Китай\n" +
423 " * 2 Государство Шан-Инь\n" +
424 " * 3 Государство Чжоу (XI—III вв. до н. э.)\n" +
425 " * 4 Империя Цинь\n" +
426 " * 5 Империя Хань\n" +
427 " * 6 Государство Цзинь и период Нань-бэй чао (IV—VI вв.)\n" +
428 " * 7 Государство Суй (581—618)\n" +
429 " * 8 Государство Тан\n" +
430 " * 9 Государство Сун\n" +
431 " * 10 Монголы и государство Юань (1280—1368)\n" +
432 " * 11 Государство Мин (1368—1644)\n" +
433 " * 12 Государство Цин\n" +
434 " o 12.1 Внешняя экспансия Цин\n" +
435 " o 12.2 Цинский Китай и Россия\n" +
436 " o 12.3 Опиумные войны\n" +
437 " o 12.4 Японо-китайская война 1894—1895 годов\n" +
438 " o 12.5 Тройственная интервенция\n" +
439 " o 12.6 Успехи русской политики в Китае\n" +
440 " o 12.7 Захват Цзяочжоу Германией\n" +
441 " o 12.8 Сто дней реформ\n" +
442 " * 13 XX век\n" +
443 " o 13.1 Боксерское восстание\n" +
444 " o 13.2 Русско-японская война\n" +
445 " o 13.3 Смерть Цыси\n" +
446 " o 13.4 Аннексия Кореи\n" +
447 " o 13.5 Революция 1911 года и создание Китайской Республики\n" +
448 " o 13.6 Первая мировая война\n" +
449 " o 13.7 Эра милитаристов\n" +
450 " o 13.8 Победа Гоминьдана\n" +
451 " o 13.9 Японская оккупация и Вторая мировая война\n" +
452 " o 13.10 Создание Китайской Народной Республики\n" +
453 " o 13.11 Культурная революция\n" +
454 " o 13.12 Экономическая либерализация\n" +
455 " * 14 См. также\n" +
456 " * 15 Литература\n" +
457 "\n" +
458 "[править] Древний Китай\n" +
459 "\n" +
460 … ближневосточные виды злаков (пшеница и ячмень) и породы домашнего скота (коровы, овцы, козы).\n" +
461 "\n" +
462 "[править] Государство Шан-Инь\n" +
463 "\n" +
464 … Шан-Инь, сформировавшееся в XIV веке до н. э. в среднем течении реки Хуанхэ, в районе Аньяна.\n" +
465 "\n" +
466 …ы. Иньцы практиковали человеческие жертвоприношения — чаще всего в жертву приносились пленные.\n" +
467 "\n" +
468 …одилось в вассальных отношениях с иньцами, но постепенно укрепилось и создало коалицию племён.\n" +
469 "\n" +
470 "[править] Государство Чжоу (XI—III вв. до н. э.)\n" +
471 "Китайская медная монета в виде мотыги. Провинция Лоян, V-III в. до н.э.\n" +
472 "Китайская медная монета в виде мотыги. Провинция Лоян, V-III в. до н.э.\n" +
473 "\n" +
474 … уделов постепенно сокращалось, а сами уделы укреплялись и становились более самостоятельными.\n" +
475 "\n" +
476 … землях на востоке, где была построена новая столица — Чэнчжоу (современная провинция Хэнань).\n" +
477 "\n" +
478 …ов (впоследствии — царств), что способствовало созданию фундамента будущей китайской общности.\n" +
479 "\n" +
480 … здесь новый удел Цинь. Впоследствии именно этот удел станет центром единой китайской империи.\n" +
481 "\n" +
482 "Период Восточное Чжоу, в свою очередь, разделяется на два периода:\n" +
483 "\n" +
484 " * Чуньцю ( «Период Весны и Осени» VIII—V вв. до н. э.);\n" +
485 " * Чжаньго («Период Сражающихся царств», V—III вв. до н. э.).\n" +
486 "\n" +
487 …ебя «срединными государствами» (чжун-го), ведущими своё происхождение от раннечжоуских уделов.\n" +
488 "\n" +
489 … — конфуцианство (VI—V вв. до н. э.), моизм (V в. до н. э.), даосизм (IV в. до н. э.), легизм.\n" +
490 "\n" +
491 …ирригационные системы, развиваются ремёсла, революционные изменения происходят в военном деле.\n" +
492 "\n" +
493 …. э. правитель Цинь — будущий император Цинь Ши Хуан — объединил весь Китай под своей властью.\n" +
494 "\n" +
495 "Так в середине III века до н. э. завершился период Восточного Чжоу.\n" +
496 "\n" +
497 "[править] Империя Цинь\n" +
498 "\n" +
499 …н и разделил огромную страну на 36 новых областей, которые возглавили назначаемые губернаторы.\n" +
500 "\n" +
501 …соединены значительные территории племён юэ, в том числе северная часть современного Вьетнама.\n" +
502 …0 км, было начато в III веке до н. э. для защиты северных районов Китая от набегов кочевников.\n" +
503 …0 км, было начато в III веке до н. э. для защиты северных районов Китая от набегов кочевников.\n" +
504 "\n" +
505 …сочинения — за то, что они смели выступать против установившегося в стране жесточайшего гнёта.\n" +
506 "\n" +
507 "Империя Цинь прекратила существование вскоре после смерти Цинь Шихуанди.\n" +
508 "\n" +
509 "[править] Империя Хань\n" +
510 "\n" +
511 …енного царства Чу, воевавших против Цинь после смерти императора Цинь Шихуана в 210 г. до н.э.\n" +
512 "\n" +
513 …ий и войн значительно сократилась численность сельского населения в основных аграрных районах.\n" +
514 "\n" +
515 … из них, кто мог захватить столицу и насильственно отстранить правившего императора от власти.\n" +
516 "\n" +
517 …95 до н.э.) начинается новый период китайской истории, который получил название Западная Хань.\n" +
518 "\n" +
519 …еловечной практикой. Именно с этого времени берёт своё начало китайская конфуцианская империя.\n" +
520 "\n" +
521 …орейское государство Чосон, присоеденены земли на юго-западе, сюнну оттеснены далее на севере.\n" +
522 "\n" +
523 …яет себе оазисы-протогосударства вдоль Шёлкового пути и распространяет своё влияние до Памира.\n" +
524 "\n" +
525 "В I в. н. э. в Китай из Индии начинает проникать буддизм.\n" +
526 "\n" +
527 … Лю за возвращение престола. Ван Ман был убит, столица взята, власть возвратилась династии Лю.\n" +
528 "\n" +
529 "Новый период получил название Восточная Хань, он продлился до 220 г. н. э.\n" +
530 "\n" +
531 "[править] Государство Цзинь и период Нань-бэй чао (IV—VI вв.)\n" +
532 "\n" +
533 …В ходе борьбы за власть между военачальниками было основано новое государство Цзинь (265—420).\n" +
534 "\n" +
535 …знати бежала на юг и юго-восток, основанное там государство получило название Восточная Цзинь.\n" +
536 "\n" +
537 … которые, однако, принимают классические китайские названия (Чжао, Янь, Лян, Цинь, Вэй и др.).\n" +
538 "\n" +
539 …таизации. К концу VI века потомки кочевников практически полностью ассимилируются с китайцами.\n" +
540 "\n" +
541 … сказано, захватчики-сяньбийцы ассимилировались с подавляющим большинством местного населения.\n" +
542 "\n" +
543 …строительство новых городов и развитие старых. На юге сосредоточился центр китайской культуры.\n" +
544 "\n" +
545 …нскрита на китайский древние буддийские тексты. Буддизм постепенно стал процветающей религией.\n" +
546 "\n" +
547 "[править] Государство Суй (581—618)\n" +
548 "\n" +
549 …станавливает и строит новые участки Великой китайской стены, пришедшей в упадок за тысячу лет.\n" +
550 "\n" +
551 …бивают, а династию Суй сменяет династия Тан (618—907), основатель — шансийский феодал Ли Юань.\n" +
552 "\n" +
553 "[править] Государство Тан\n" +
554 "\n" +
555 …ская жизнь. Значительно увеличились размеры многих городов и численность городского населения.\n" +
556 "\n" +
557 …рё покорено и становится Аньдунским наместничеством Китая. Вновь открыт Великий шёлковый путь.\n" +
558 "\n" +
559 …Китае получают распространение новые сельскохозяйственные культуры — в частности, чай, хлопок.\n" +
560 "\n" +
561 …нчжоу (Кантон), с Индией и Ираном, Арабским Халифатом, корейским государством Силла и Японией.\n" +
562 "\n" +
563 …на периферии. Окончательно господство династии Лю подрывает война Хуан Чао за престол 874—901.\n" +
564 "\n" +
565 …единую государственную власть, что связано с междоусобными войнами, особенно на севере страны.\n" +
566 "\n" +
567 "[править] Государство Сун\n" +
568 "\n" +
569 …толетия Сун прошли под знаком успешного давления на Китай со стороны северных степных народов.\n" +
570 "\n" +
571 …ату дани. В 1042 дань была увеличена, а в 1075 Китай отдал киданям ещё часть своей территории.\n" +
572 "\n" +
573 …автономного района. С 1047 Сунской империи пришлось и тангутам платить дань серебром и шёлком.\n" +
574 "\n" +
575 …ованное внедрение и распространение новых сортов скороспелого риса из Южного Вьетнама (Чампы).\n" +
576 "Чжан Цзэдуань. «По реке в День поминовения усопших» (XII век).\n" +
577 "Чжан Цзэдуань. «По реке в День поминовения усопших» (XII век).\n" +
578 "\n" +
579 … районе рек Талас и Чу сложилось небольшое государство кара-китаев — Западное Ляо (1124—1211).\n" +
580 "\n" +
581 …. Северный Китай вновь на длительное время оказывается под господством иноземных завоевателей.\n" +
582 "\n" +
583 …сно которому Сунская империя признаёт себя вассалом империи Цзинь и обязуется платить ей дань.\n" +
584 "\n" +
585 "[править] Монголы и государство Юань (1280—1368)\n" +
586 "\n" +
587 …небольшие родоплеменные коллективы, связанные общностью происхождения, языка, культуры и т. п.\n" +
588 "\n" +
589 …возглашён победивший в жестокой междоусобной борьбе Темучин, принявший имя и титул Чингисхана.\n" +
590 "\n" +
591 …ла решающим фактором в последующих успехах сравнительно немногочисленного монгольского этноса.\n" +
592 "\n" +
593 …соседние народы Южной Сибири, Чингисхан в 1210 пошёл войной на чжурчжэней и в 1215 взял Пекин.\n" +
594 "\n" +
595 …нголов вернулись в Северный Китай и к 1234 завершили разгром чжурчжэньского государства Цзинь.\n" +
596 "\n" +
597 …лам удалось взять лишь в 1276. К 1280 весь Китай был завоёван, а Сунская империя — уничтожена.\n" +
598 "\n" +
599 …юрки и даже европейцы — в частности, в это время Китай посещает венецианский купец Марко Поло.\n" +
600 "\n" +
601 …ких сот тысяч человек. Великтий Китайский канал был построен во время монгольского господства.\n" +
602 "\n" +
603 …ние и восстания, которые возглавили руководители тайного общества «Белый лотос» (Байляньцзяо).\n" +
604 "\n" +
605 "[править] Государство Мин (1368—1644)\n" +
606 "\n" +
607 …руководителей восстания — сын крестьянина Чжу Юаньчжан, основавший государствоМин (1368—1644).\n" +
608 "\n" +
609 …ьчжао (современные провинции Юньнань и Гуйчжоу), часть современных провинций Цинхай и Сычуань.\n" +
610 "\n" +
611 …принеся Китаю никакой экономической выгоды, экспедиции были прекращены, а корабли — разобраны.\n" +
612 "\n" +
613 …производство огнестрельного оружия. В то же время они занимаются доскональным изучением Китая.\n" +
614 "\n" +
615 "[править] Государство Цин\n" +
616 "\n" +
617 …а Китай. За восемь лет они выходят практически к Великой китайской стене (на крайнем востоке).\n" +
618 "\n" +
619 …Маньчжурии и захваченных ханств Южной Монголии устанавливается централизованная администрация.\n" +
620 "\n" +
621 …жи правителем всего Китая. У Саньгуй вместе со всей армией переходит на службу к завоевателям.\n" +
622 "\n" +
623 …и организованному войску. Последний оплот сопротивления — Тайвань захвачен маньчжурами в 1683.\n" +
624 "\n" +
625 …ались, тем более что, в отличие от монголов, они не противопоставляли себя китайской культуре.\n" +
626 "\n" +
627 …кого населения, но при этом заботились о процветании экономики страны и благосостоянии народа.\n" +
628 "\n" +
629 "[править] Внешняя экспансия Цин\n" +
630 "\n" +
631 … пунктом иностранной торговли оставался остров Макао, находившийся под контролем португальцев.\n" +
632 "\n" +
633 …являл себя как сильное независимое государство, осуществляющее экспансию во всех направлениях.\n" +
634 "\n" +
635 …1765—1769) и Вьетнама (1788—1789) оказались неудачными и закончились поражением цинских войск.\n" +
636 "\n" +
637 …рными зонами — Маньчжурией, Монголией, Тибетом, Синьцзяном — которые охраняли китайские земли.\n" +
638 "\n" +
639 …атривались исключительно как представители вассальных государств — реальных или потенциальных.\n" +
640 "\n" +
641 "[править] Цинский Китай и Россия\n" +
642 "\n" +
643 " Основная статья: Российско-китайские отношения\n" +
644 "\n" +
645 …вели к присоединению его к России, в то время как маньчжуры считали эти районы своей вотчиной.\n" +
646 "\n" +
647 … Албазинское) воеводство, в которое входила долина Верхнего и Среднего Амура по обоим берегам.\n" +
648 "\n" +
649 … властям на Амуре полномочное посольство Фёдора Головина для мирного урегулирования конфликта.\n" +
650 "\n" +
651 …ё Албазинское воеводство, всё Забайкалье, а впоследствии — вообще все земли к востоку от Лены.\n" +
652 "\n" +
653 …о-китайское территориальное разграничение в Центральной Азии было завершено к середине 1890-х.\n" +
654 "\n" +
655 "[править] Опиумные войны\n" +
656 "Территория собственно Китая в 1875\n" +
657 "Территория собственно Китая в 1875\n" +
658 "\n" +
659 … войнах привело к постепенному превращению Китая в фактическую полуколонию европейских держав.\n" +
660 "\n" +
661 "[править] Японо-китайская война 1894—1895 годов\n" +
662 "\n" +
663 …ого короля проведения «реформ», означавших фактически установление в Корее японского контроля.\n" +
664 "\n" +
665 …официальное объявление войны последовало только 1 августа 1894. Началась Японо-китайская война\n" +
666 "\n" +
667 …ше и на море (под Асаном, июль 1894; под Пхеньяном, сентябрь 1894; при Цзюляне, октябрь 1894).\n" +
668 "\n" +
669 …онские войска захватили Ляодунский полуостров, Вэйхайвэй, Инкоу, под угрозой находился Мукден.\n" +
670 "\n" +
671 …имоносеки представители Японии и Китая подписали унизительный для Китая Симоносекский договор.\n" +
672 "\n" +
673 "[править] Тройственная интервенция\n" +
674 "\n" +
675 …зающий порт для России. Германская нота была наиболее жесткой, даже оскорбительной для Японии.\n" +
676 "\n" +
677 … полуострова, правда, добившись увеличения суммы китайской контрибуции на 30 миллионов таэлей.\n" +
678 "\n" +
679 "[править] Успехи русской политики в Китае\n" +
680 "\n" +
681 …был подписан русско-китайский договор об аренде Россией Порт-Артура и Ляодунского полуострова.\n" +
682 "\n" +
683 "[править] Захват Цзяочжоу Германией\n" +
684 "\n" +
685 …концессию на постройку двух железных дорог в Шаньдуне и ряд горных концессий в этой провинции.\n" +
686 "\n" +
687 "[править] Сто дней реформ\n" +
688 "\n" +
689 …же года, когда вдовствующая Императрица Цыси произвела дворцовый переворот и отменила реформы.\n" +
690 "\n" +
691 "[править] XX век\n" +
692 "\n" +
693 "[править] Боксерское восстание\n" +
694 "\n" +
695 …ередовым отрядом под командованием русского генерала Линевича. Русская армия заняла Манчжурию.\n" +
696 "\n" +
697 "[править] Русско-японская война\n" +
698 "\n" +
699 …а уступить Японии Порт-Артур и Ляодунский полуостров с частью построенной к тому времени КВЖД.\n" +
700 "\n" +
701 "[править] Смерть Цыси\n" +
702 "\n" +
703 …ыло два года. Регентом назначен его отец князь Чунь, однако вскоре власть перешла к его брату.\n" +
704 "\n" +
705 "[править] Аннексия Кореи\n" +
706 "\n" +
707 …пония аннексировала Корею, хотя японские войска там находились с начала Русско-японской войны.\n" +
708 "\n" +
709 "[править] Революция 1911 года и создание Китайской Республики\n" +
710 "\n" +
711 …оторой было свергнута маньчжурская династия Цин и провозглашено создание Китайской республики.\n" +
712 "\n" +
713 …нглийской сферой влияния, а Англия признала русские интересы в независимой (внешней) Монголии.\n" +
714 "\n" +
715 …икай премьер-министр и главнокомандующий армией. Вскоре он был провозглашен президентом Китая.\n" +
716 "\n" +
717 …ля группировки бэйянских (северных) милитаристов. Сунь Ятсен вынужден эмигрировать за границу.\n" +
718 "\n" +
719 "[править] Первая мировая война\n" +
720 "\n" +
721 …манские владения в Шаньдуне, а также распространила свой контроль на всю территорию провинции.\n" +
722 "\n" +
723 …ляют провинции Юньнань, Гуйчжоу и Гуанси. Потом отделяются Гуандун, Чжэцзян, Сычуань и Хунань.\n" +
724 "\n" +
725 "22 марта 1916 года умирает Юань Шикай.\n" +
726 "\n" +
727 "[править] Эра милитаристов\n" +
728 "\n" +
729 …к: юньнаньской во главе с генералом Тан Цзияо, и гуансийской во главе с генералом Лу Жунтином.\n" +
730 "\n" +
731 …ю крупные займы, получая за них все новые и новые уступки, в том числе концессии в Маньчжурии.\n" +
732 "\n" +
733 "[править] Победа Гоминьдана\n" +
734 "\n" +
735 …4 г. в Гуанчжоу на должность главного военного советника прибыл Василий Константинович Блюхер.\n" +
736 …ласти, Чан Кайши пригласил немецких советников во главе бывшим генералом рейхсвера фон Сектом.\n" +
737 "В качестве советников у Чан Кайши действовали офицеры Германии:\n" +
738 "\n" +
739 " * полковник В.Бауэр (друг Гитлера и ученик Людендорфа)\n" +
740 " * нацист подполковник Крибель\n" +
741 " * генерал-лейтенант Ветцель\n" +
742 " * генерал Фалькенхаузен\n" +
743 "\n" +
744 …ядка в стране. Китайские офицеры в организованном порядке направлялись на обучение в Германию.\n" +
745 …прерывных боев от власти местных военных правителей были освобождены центральные районы Китая.\n" +
746 …восстание части гоминьдановских войск, вошедшее в историю Китая как \"Наньчанское восстание\".\n" +
747 …не, которое гоминьдановцы жесточайшим образом подавили после четырех дней кровопролитных боев.\n" +
748 … военных операций к 1927 году войска Гоминьдана контролировали большую часть территории Китая.\n" +
749 "\n" +
750 "[править] Японская оккупация и Вторая мировая война\n" +
751 "\n" +
752 …л Пу И – последний отпрыск маньчжурской династии Цин, свергнутой в годы Синьхайской революции.\n" +
753 "\n" +
754 …ского инцидента\" было подписано соглашение о создании единого фронта между КПК и Гоминьданом.\n" +
755 "\n" +
756 …льшая» война. С этого момента, по мнению китайских историков, начинается Вторая мировая война.\n" +
757 "\n" +
758 "\n" +
759 " Этот раздел не завершён. Вы можете помочь проекту, исправив и дополнив его.\n" +
760 "Японская оккупация (1940)\n" +
761 "Японская оккупация (1940)\n" +
762 "\n" +
763 "[править] Создание Китайской Народной Республики\n" +
764 "\n" +
765 …орабощения страны Азиатско-Тихоокеанского региона. В Китае шла ожесточенная гражданская война.\n" +
766 …Манчжурии действовали лишь разрозненные партизанские отряды и разведгруппы китайских партизан.\n" +
767 …ческая армия (ОДА) Северо-Востока, которая стала костяком Народно-освободительной армии Китая.\n" +
768 … а современную дисциплинированную армию коммунистов, вовсе не намеревавшуюся самораспускаться.\n" +
769 … 30 сентября 1945. К осени в Китае находилось уже свыше 100 тысяч американских военнослужащих.\n" +
770 …м Китае, а также в поддержании порядка и охране различных важных объектов в китайских городах.\n" +
771 …ичтожение партизанского движения и партизанских баз в Центральном, Восточном и Северном Китае.\n" +
772 …00 тысяч человек. С 1 ноября ОДА стала именоваться 4-й Полевой армией. возглавили ее Линь Бяо.\n" +
773 …й, где объединилась с войсками 8-й армии КПК. 15 января был взят Тяньцзинь, 22 января - Пекин.\n" +
774 … Народно-освободительная армия представляла собой мощную 4-миллионую армию, крупнейшую в Азии.\n" +
775 …а юг страны, в Кантон, а затем вместе с остатками верных ему войск - бежало на остров Тайвань.\n" +
776 …вки Гоминьдана на континенте, победоносно завершив тем самым третью гражданскую войну в Китае.\n" +
777 "1 октября 1949 г. в Пекине была провозглашена Китайская Народная Республика.\n" +
778 …лся советско-китайский «монолит» - тот самый, который на многие годы стал кошмаром для Запада.\n" +
779 "\n" +
780 "[править] Культурная революция\n" +
781 "\n" +
782 …революционеров» из числа аппарата КПК, интеллигенции и вообще всех, кто мог им не понравиться.\n" +
783 "\n" +
784 "[править] Экономическая либерализация\n" +
785 "\n" +
786 …трирует высказываение Д.Сяопина: \"Неважно какого цвета кошка - главное, чтобы ловила мышей\".\n" +
787 "\n" +
788 …йная хозяйственная система на основе сочетания коллективной собственности и семейного подряда.\n" +
789 "\n" +
790 …ько сотен миллионов заняты частично. Официальный уровень безработицы в городах 4,2% (2005 г.).\n" +
791 "\n" +
792 …елей/сут. в 2005-м, 2-е место в мире) приводит в последние годы к росту ее среднемировой цены.\n" +
793 "\n" +
794 …у в немалой степени способствует и РФ, поставляющая в Китай самые современные виды вооружения.\n" +
795 "\n" +
796 …д). Несмотря на такую суровую практику, уровень преступности и коррупции постоянно возрастает.\n" +
797 "\n" +
798 …мание, что уже затрагивает не только территорию Китая, но и интересы сопредельных с ним стран.\n" +
799 "\n" +
800 "[править] См. также\n" +
801 "\n" +
802 " * Китай (цивилизация)\n" +
803 " * События на площади Тяньаньмэнь 1989 года\n" +
804 "\n" +
805 "[править] Литература\n" +
806 "\n" +
807 …3 т. Т. 3. Период Чжаньго (V–III вв. до н.э.). М.: Восточная литература, 2006. ISBN 502018103X\n" +
808 …стория Китая: Эпоха Цин. XVII – начало XX века. М.: Восточная литература, 2005. ISBN 5020184004\n";
811 "भारत\n" +
812 "विकिपीडिया, एक मुक्त ज्ञानकोष से\n" +
813 "Jump to: navigation, search\n" +
814 …ए और इस लेख को निर्वाचित लेख बनने के लिए क्या आवश्यकताएँ हैं यह जानने के लिए कृपया यहाँ देखें।\n" +
815 "भारत गणराज्य\n" +
816 "Flag of भारत Coat of arms of भारत\n" +
817 "ध्वज कुलचिह्न\n" +
818 "राष्ट्रवाक्य: \"सत्यमेव जयते\" (संस्कृत)\n" +
819 "\n" +
820 "सत्य ही विजयी होता है\n" +
821 "राष्ट्रगान: जन गण मन\n" +
822 "भारत की स्थिति\n" +
823 "राजधानी नई दिल्ली\n" +
824 "८७, ५९०) 28°34′ N 77°12′ E\n" +
825 "सबसे बड़ा शहर मुम्बई\n" +
826 "राजभाषा(एँ) हिन्दी, अंग्रेज़ी तथा अन्य भारतीय भाषाएं\n" +
827 "सरकार\n" +
828 "राष्ट्रपति\n" +
829 "प्रधानमंत्री\n" +
830 " गणराज्य\n" +
831 "प्रतिभा पाटिल\n" +
832 "डॉ मनमोहन सिंह\n" +
833 "ब्रिटिश राज से स्वतंत्रता\n" +
834 " १५ अगस्त, १९४७\n" +
835 "क्षेत्रफल\n" +
836 " - कुल\n" +
837 " \n" +
838 " - जलीय (%) \n" +
839 "३२, ८७, ५९० km² (सातवां)\n" +
840 "१२,२२,५५९ sq mi \n" +
841 "९.५६\n" +
842 "जनसंख्या\n" +
843 " - २००५ अनुमान\n" +
844 " - २००१ जनगणना\n" +
845 " - जनसंख्या का घनत्व \n" +
846 "१,१०,३३,७१,००० (द्वितीय)\n" +
847 "१,०२,७०,१५,२४८\n" +
848 "३२९/km² (३१ वीं)\n" +
849 "८५२/sq mi \n" +
850 "सकल घरेलू उत्पाद (जीडीपी) (पीपीपी)\n" +
851 " - कुल\n" +
852 " - प्रतिव्यत्ति २००५ estimate\n" +
853 "$३.६३३ महासंख (चौथी GDP_PPP_per_capita = $३,३२०)\n" +
854 "{{{GDP_PPP_per_capita}}} (१२२ वीं)\n" +
855 "मानव विकास संकेतांक (एइचडीआइ) ०.६११ (१२६ वीं) – medium\n" +
856 "मुद्रा भारतीय रुपया (आइएनआर)\n" +
857 "समय मण्डल\n" +
858 " - ग्रीष्म ऋतु (डेलाइट सेविंग टाइम) आइएसटी (UTC+५:३०)\n" +
859 "अब्सर्व्ड नहीं है (UTC+५:३०)\n" +
860 "इंटरनेट टॉप लेवेल डोमेन .आइएन\n" +
861 "दूरभाष कोड +९१\n" +
862 "\n" +
863 …ाती है। अन्य बड़ी नदियाँ ब्रह्मपुत्र, यमुना, गोदावरी, कावेरी, कृष्णा, चम्बल, सतलज, बियास हैं ।\n" +
864 "\n" +
865 …ै। यहाँ ३०० से अधिक भाषाएँ बोली जाती है (साइटेसन चाहिए)। यह एक बहुत प्राचीन सभ्यता की भूमि है।\n" +
866 "\n" +
867 … की है, विशेष रूप से आर्थिक और सैन्य | भारतीय सेना एक क्षेत्रिय शक्ति और विश्वव्यापक शक्ति है।\n" +
868 "\n" +
869 … दिल्ली है। भारत के अन्य बड़े महानगर मुम्बई (बम्बई), कोलकाता (कलकत्ता) और चेन्नई (मद्रास) हैं।\n" +
870 "\n" +
871 "\n" +
872 "अनुक्रम\n" +
873 "[छुपाएं]\n" +
874 "\n" +
875 " * १ नाम\n" +
876 " * २ इतिहास\n" +
877 " * ३ सरकार\n" +
878 " * ४ राजनीति\n" +
879 " * ५ राज्य और केन्द्रशासित प्रदेश\n" +
880 " * ६ भूगोल और मौसम\n" +
881 " * ७ अर्थव्यवस्था\n" +
882 " * ८ जनवृत्त\n" +
883 " * ९ संस्कृति\n" +
884 " * १० यह भी देखें\n" +
885 " * ११ बाहरी कड़ियाँ\n" +
886 "\n" +
887 "[संपादित करें] नाम\n" +
888 "मुख्य लेख: भारत नाम की उत्पत्ति\n" +
889 "\n" +
890 …त्पत्ति फारसी) या हिन्दुओं की भूमि मुगल काल से प्रयोग होता है यद्यपि इसका समकालीन उपयोग कम है।\n" +
891 "\n" +
892 "[संपादित करें] इतिहास\n" +
893 "मुख्य लेख: भारतीय इतिहास\n" +
894 "\n" +
895 …ोनो जातियों ने एक दूसरे की खूबियों को अपनाते हुए भारत में एक मिश्रित संस्कृति का निर्माण किया।\n" +
896 "\n" +
897 … तीसरी शताब्दी के आगे का समय जब भारत पर गुप्त वंश का शासन था, भारत का \"स्वर्णिम काल\" कहलाया।\n" +
898 "तीसरी शताब्दी में सम्राट अशोक द्वारा बनाया गया मध्य प्रदेश में साँची का स्तूप\n" +
899 "तीसरी शताब्दी में सम्राट अशोक द्वारा बनाया गया मध्य प्रदेश में साँची का स्तूप\n" +
900 "\n" +
901 … खगोल शास्त्र, प्राचीन प्रौद्योगिकी, धर्म, तथा दर्शन इन्हीं राजाओं के शासनकाल में फ़ले-फ़ूले |\n" +
902 "\n" +
903 …लांकि, विशेषतः तुलनात्मक रूप से, संरक्षित दक्षिण में अनेक राज्य शेष रहे अथवा अस्तित्व में आये।\n" +
904 "\n" +
905 …े जाना जाता है, के बाद भारत का अधिकांश भाग सीधे अंग्रेजी शासन के प्रशासनिक नियंत्रण में आ गया।\n" +
906 …े उड़ीसा के सूर्य मन्दिर में स्थित, यह दुनिया के सब से प्रसिद्घ ऐतिहासिक स्थानों में से एक है।\n" +
907 …े उड़ीसा के सूर्य मन्दिर में स्थित, यह दुनिया के सब से प्रसिद्घ ऐतिहासिक स्थानों में से एक है।\n" +
908 "\n" +
909 …ग्रेजी शासन से पूर्णतः स्वतंत्रता प्राप्त की। तदुपरान्त 26 जनवरी, 1950 को भारत एक गणराज्य बना।\n" +
910 "\n" +
911 … को छोड़, जब तत्कालीन प्रधानमंत्री इंदिरा गांधी ने आपातकाल की घोषणा कर दी थी, अक्षुण्य रही है।\n" +
912 "\n" +
913 …१९६२ में चीन के साथ, तथा १९४७, १९६५, १९७१ एवम् १९९९ में पाकिस्तान के साथ लड़ाइयाँ हो चुकी हैं।\n" +
914 "\n" +
915 "भारत गुटनिरपेक्ष आन्दोलन तथा संयुक्त राष्ट्र संघ के संस्थापक सदस्य देशों में से एक है।\n" +
916 "\n" +
917 …िये गये आर्थिक सुधारीकरण की बदौलत आज देश सबसे तेजी से विकासशील राष्ट्रों की सूची में आ गया है।\n" +
918 "\n" +
919 "[संपादित करें] सरकार\n" +
920 "मुख्य लेख: भारत सरकार\n" +
921 "\n" +
922 … द्वारा संचालित है। इसके शासन में तीन मुख्य अंग हैं: न्यायपालिका, कार्यपालिका और व्यवस्थापिका।\n" +
923 "\n" +
924 …। संविधान में किसी उप-प्रधानमंत्री का प्रावधान नहीं है पर समय-समय पर इसमें फेरबदल होता रहा है।\n" +
925 "\n" +
926 …िधि से, ५ वर्षों की अवधि के लिये। १८ वर्ष से अधिक उम्र के सभी भारतीय नागरिक मतदान कर सकते हैं।\n" +
927 "\n" +
928 … प्रत्येक मंत्री को संसद का सदस्य होना अनिवार्य है। कार्यपालिका, व्यवस्थापिका से नीचे होता है।\n" +
929 "\n" +
930 …षा सीमित हैं। न्यायपालिका और व्यवस्थापिका के परस्पर मतभेद या विवाद का सुलह राष्ट्रपति करता है।\n" +
931 "\n" +
932 "[संपादित करें] राजनीति\n" +
933 "मुख्य लेख: भारत की राजनीति\n" +
934 "भारत का मानचित्र\n" +
935 "भारत का मानचित्र\n" +
936 "\n" +
937 …िपक्ष जनता पार्टी ने चुनाव जीता और उसने अत्यधिक छोटी अवधि के लिये एक गैर-काँग्रेसी सरकार बनाई।\n" +
938 "\n" +
939 …परन्तु १९९१ मे बनी काँग्रेस सरकार ने अपना ५ वर्ष का कार्यकाल पूरा किया और कई आर्थिक सुधार लाई।\n" +
940 "\n" +
941 …्रीय स्तर पर उभरने के कारण १९९६ से बनी सभी सरकारों को राजनीतिक गठबन्धनों की आवश्यक्ता पड़ी है।\n" +
942 "\n" +
943 "[संपादित करें] राज्य और केन्द्रशासित प्रदेश\n" +
944 "मुख्य लेख: भारत के राज्य\n" +
945 "\n" +
946 …रदेशों पर केन्द्र द्वारा नियुक्त प्रबंधन शासन करता है, हालाँकि कुछ की लोकतांत्रिक सरकार भी है।\n" +
947 "\n" +
948 … पर भी भारत के वैज्ञानिक स्थल हैं यद्यपि अभी तक कोई वास्तविक आधिपत्य स्थापित नहीं किया गया है।\n" +
949 "\n" +
950 "[संपादित करें] भूगोल और मौसम\n" +
951 "मुख्य लेख: भारत का भूगोल\n" +
952 …र में जम्मू और काश्मीर से लेकर पूर्व में अरुणाचल प्रदेश तक भारत की अधिकतर पूर्वी सीमा बनाता है\n" +
953 …र में जम्मू और काश्मीर से लेकर पूर्व में अरुणाचल प्रदेश तक भारत की अधिकतर पूर्वी सीमा बनाता है\n" +
954 "\n" +
955 … लगभग संपूर्ण ही दक्खन के पठार से निर्मित है। यह पठार पूर्वी और पश्चिमी घाटों के बीच स्थित है।\n" +
956 "\n" +
957 …री और कृष्णा भारत से होकर बहती हैं। इन नदियों के कारण उत्तर भारत की भूमि कृषि के लिए उपजाऊ है।\n" +
958 "\n" +
959 …रसात है वहीं पश्चिम में रेगिस्तान की शुष्कता। भारत में वर्षा मुख्यतया मानसून हवाओं से होती है।\n" +
960 "\n" +
961 …ुख्य शहर है - दिल्ली, मुम्बई, कोलकाता, चेन्नई, बंगलोर ( बेंगलुरु ) | ये भी देंखे - भारत के शहर\n" +
962 "\n" +
963 "[संपादित करें] अर्थव्यवस्था\n" +
964 "मुख्य लेख: भारत की अर्थव्यवस्था\n" +
965 …ें से एक है, वार्षिक आय $२८५० करोड़ डालर, इन्फ़ोसिस, भारत की सबसे बडी आईटी कम्पनियों में से एक\n" +
966 …ें से एक है, वार्षिक आय $२८५० करोड़ डालर, इन्फ़ोसिस, भारत की सबसे बडी आईटी कम्पनियों में से एक\n" +
967 "\n" +
968 … है। १९९१ के बाद भारत मे आर्थिक सुधार की नीति ने भारत के सर्वंगीण विकास मे बडी भूमिका निभाआयी।\n" +
969 "\n" +
970 …ा प्रदान करते हैं। पिछले वषों मंे भारत में वित्तीय संस्थानो ने विकास में बड़ी भूमिका निभाई है।\n" +
971 "\n" +
972 …लर प्रदान करता है। भारत के प्रमुख व्यापार सहयोगी हैं अमरीका, जापान, चीन और संयुक्त अरब अमीरात।\n" +
973 "\n" +
974 … २००४ के लिये भारत के कुल निर्यात $६९१८ करोड़ डालर के थे जबकि उसके आयात $८९३३ करोड डालर के थे।\n" +
975 "\n" +
976 "[संपादित करें] जनवृत्त\n" +
977 "मुख्य लेख: भारत के लोग\n" +
978 "\n" +
979 … विभिन्नताओं से भरी जनता में भाषा, जाति और धर्म, सामाजिक और राजनीतिक संगठन के मुख्य शत्रु हैं।\n" +
980 "हिन्दुत्व भारत का सबसे बङा धर्म है - इस चित्र मे गोआ का एक मंदिर दर्शाया गया है\n" +
981 "हिन्दुत्व भारत का सबसे बङा धर्म है - इस चित्र मे गोआ का एक मंदिर दर्शाया गया है\n" +
982 "\n" +
983 …की १००० जनसंख्या में २२.३२ जन्मों के साथ बढती जनसंख्या के आधे लोग २२.६६ वर्ष से कम आयु के हैं।\n" +
984 "\n" +
985 …बौद्ध (०.७६ %), जैन (०.४० %), अय्यावलि (०.१२ %), यहूदी, पारसी, अहमदी और बहाई आदि सम्मिलित हैं।\n" +
986 "\n" +
987 … भारत में ही जन्मी हैं। कुल मिलाकर भारत में १६५२ से भी अधिक भाषाएं एवं बोलियाँ बोली जातीं हैं।\n" +
988 "\n" +
989 "[संपादित करें] संस्कृति\n" +
990 "मुख्य लेख: भारतीय संस्कृति\n" +
991 "ताजमहल विश्व के सबसे प्रसिद्ध पर्यटक स्थलों में गिना जाता है।\n" +
992 "ताजमहल विश्व के सबसे प्रसिद्ध पर्यटक स्थलों में गिना जाता है।\n" +
993 "\n" +
994 …ि इसका प्रमाण हैं। ताजमहल और अन्य उदाहरण, इस्लाम प्रभावित स्थापत्य कला के अतिसुन्दर नमूने हैं।\n" +
995 "गुम्पा नृत्य एक तिब्बती बौद्ध समाज का सिक्किम में छिपा नृत्य है। यह बौद्ध नव बर्ष में है।\n" +
996 "गुम्पा नृत्य एक तिब्बती बौद्ध समाज का सिक्किम में छिपा नृत्य है। यह बौद्ध नव बर्ष में है।\n" +
997 "\n" +
998 … मिश्र-सांस्कृतिक है। पारंपरिक भारतीय पारिवारिक मूल्यों को काफी आदर की दृष्टि से देखा जाता है।\n" +
999 "\n" +
1000 …ी, होली, दशहरा. पोंगल तथा ओणम . ईद-उल-फितर, मुहर्रम, क्रिसमस, ईस्टर आदि भी काफ़ी लोकप्रिय हैं।\n" +
1001 "\n" +
1002 … विश्व कीर्तिमान है। शतरंज के जनक देश भारत के खिलाड़ी शतरंज में भी अच्छा प्रदर्शन करते आए हैं।\n" +
1003 "\n" +
1004 …हारी दोनो तरह का खाना पसन्द किया जाता है। भारतीय व्यंजन विदेशों में भी बहुत पसन्द किए जाते है।\n" +
1005 "\n" +
1006 …्य शैली है। हिन्दुस्तानी संगीत तथा कर्नाटक संगीत भारतीय परंपरागत संगीत की दो मुख्य धाराएं हैं।\n" +
1007 "\n" +
1008 …िष्कारों का भारत में प्रयोग अनुचित भी समझते हैं। हालाँकि ऐसे कई लोग है जो ऐसा विचार नहीं रखते।\n" +
1009 "\n" +
1010 "[संपादित करें] यह भी देखें\n" +
1011 "\n" +
1012 " * दक्षिण भारत\n" +
1013 " * उत्तर पूर्वी भारत\n" +
1014 " * भारत की भाषाएँ\n" +
1015 "\n" +
1016 "\n" +
1017 "[संपादित करें] बाहरी कड़ियाँ\n" +
1018 "\n" +
1019 "सरकार (हिन्दी)\n" +
1020 "\n" +
1021 " * भारत का राष्ट्रीय पोर्टल\n" +
1022 "\n" +
1023 "सरकार (अंग्रेज़ी)\n" +
1024 "\n" +
1025 " * भारतीय सरकार का सरकारी वैबसाइट\n" +
1026 " * भारतीय सरकार का वेबसाइट का सरकारी निर्देशिका\n" +
1027 "\n" +
1028 "सेनापति निर्देश (अंग्रेज़ी)\n" +
1029 "\n" +
1030 " * सीआईए में भारत निबन्ध\n" +
1031 " * एन्साक्लोपीडिया ब्रिटैनिका का भारत निबन्ध\n" +
1032 " * बीबीसी का भारत निबन्ध\n" +
1033 "\n" +
1034 "भारत का देश नक्शा\n" +
1035 "\n" +
1036 "सैटेलाइट चित्र (अंग्रेज़ी)\n" +
1037 "\n" +
1038 " * गूगल मानचित्र से भारत का सैटेलाइट चित्र\n" +
1039 "\n" +
1040 "अन्य (अंग्रेज़ी)\n" +
1041 "\n" +
1042 " * विकिभ्रमण का भारत निबन्ध\n" +
1043 " * भारत ओपेन डायरैक्टरी प्रॉजेक्ट में\n" +
1044 " * भारत यात्रा - सामूहिक यात्रा ब्लॉग\n";
1047 "English language\n" +
1048 "From Wikipedia, the free encyclopedia\n" +
1049 "• Learn more about citing Wikipedia •\n" +
1050 "Jump to: navigation, search\n" +
1051 " Editing of this article by unregistered or newly registered users is currently disabled.\n" +
1052 … you can discuss changes on the talk page, request unprotection, log in, or create an account.\n" +
1053 "English \n" +
1054 "Pronunciation: /ˈɪŋɡlɪʃ/[37]\n" +
1055 "Spoken in: Listed in the article\n" +
1056 "Total speakers: First language: 309[38] – 380 million[3]\n" +
1057 "Second language: 199[39] – 600 million[40]\n" +
1058 "Overall: 1.8 billion[41] \n" +
1059 "Ranking: 3 (native speakers)[9][10]\n" +
1060 "Total: 1 or 2 [11]\n" +
1061 "Language family: Indo-European\n" +
1062 " Germanic\n" +
1063 " West Germanic\n" +
1064 " Anglo–Frisian\n" +
1065 " Anglic\n" +
1066 " English \n" +
1067 "Writing system: Latin (English variant) \n" +
1068 "Official status\n" +
1069 "Official language of: 53 countries\n" +
1070 "Flag of the United Nations United Nations\n" +
1071 "Regulated by: no official regulation\n" +
1072 "Language codes\n" +
1073 "ISO 639-1: en\n" +
1074 "ISO 639-2: eng\n" +
1075 "ISO 639-3: eng \n" +
1076 … language are light blue. English is also one of the official languages of the European Union.\n" +
1077 …honetic symbols in Unicode. See IPA chart for English for an English-based pronunciation key.\n" +
1078 "\n" +
1079 … such as India, Sri Lanka, Pakistan and South Africa, and in many international organisations.\n" +
1080 "\n" +
1081 …tural influence of the United States has significantly accelerated the spread of the language.\n" +
1082 "\n" +
1083 …nguage learning and teaching). English is one of six official languages of the United Nations.\n" +
1084 "Contents\n" +
1085 "[hide]\n" +
1086 "\n" +
1087 " * 1 History\n" +
1088 " * 2 Classification and related languages\n" +
1089 " * 3 Geographical distribution\n" +
1090 " o 3.1 English as a global language\n" +
1091 " o 3.2 Dialects and regional varieties\n" +
1092 " o 3.3 Constructed varieties of English\n" +
1093 " * 4 Phonology\n" +
1094 " o 4.1 Vowels\n" +
1095 " + 4.1.1 See also\n" +
1096 " o 4.2 Consonants\n" +
1097 " + 4.2.1 Voicing and aspiration\n" +
1098 " o 4.3 Supra-segmental features\n" +
1099 " + 4.3.1 Tone groups\n" +
1100 " + 4.3.2 Characteristics of intonation\n" +
1101 " * 5 Grammar\n" +
1102 " * 6 Vocabulary\n" +
1103 " o 6.1 Number of words in English\n" +
1104 " o 6.2 Word origins\n" +
1105 " + 6.2.1 Dutch origins\n" +
1106 " + 6.2.2 French origins\n" +
1107 " * 7 Writing system\n" +
1108 " o 7.1 Basic sound-letter correspondence\n" +
1109 " o 7.2 Written accents\n" +
1110 " * 8 Formal written English\n" +
1111 " * 9 Basic and simplified versions\n" +
1112 " * 10 Notes\n" +
1113 " * 11 References\n" +
1114 " * 12 See also\n" +
1115 " * 13 External links\n" +
1116 " o 13.1 Dictionaries\n" +
1117 "\n" +
1118 "History\n" +
1119 "\n" +
1120 " Main article: History of the English language\n" +
1121 "\n" +
1122 …re of a new ruling class, or a combination of both of these processes (see Sub-Roman Britain).\n" +
1123 "\n" +
1124 … settled mainly in the north and the east coast down to London, the area known as the Danelaw.\n" +
1125 "\n" +
1126 … the seventeenth century there was a reaction in some circles against so-called inkhorn terms.\n" +
1127 "\n" +
1128 … effect of printing. Early Modern English can be traced back to around the Elizabethan period.\n" +
1129 "\n" +
1130 "Classification and related languages\n" +
1131 "\n" +
1132 …ngs to the western sub-branch of the Germanic branch of the Indo-European family of languages.\n" +
1133 "\n" +
1134 …languages of Scandinavia are less closely related to English than the West Germanic languages.\n" +
1135 "\n" +
1136 …), as well as occasional divergences in meaning, in so-called \"faux amis\", or false friends.\n" +
1137 "\n" +
1138 "Geographical distribution\n" +
1139 "\n" +
1140 " See also: List of countries by English-speaking population\n" +
1141 "\n" +
1142 …ome who claim that non-native speakers now outnumber native speakers by a ratio of 3 to 1.[15]\n" +
1143 "\n" +
1144 …han any other country in the world.[22] Following India is the People's Republic of China.[23]\n" +
1145 "Distribution of native English speakers by country (Crystal 1997)\n" +
1146 "Distribution of native English speakers by country (Crystal 1997)\n" +
1147 " Country Native speakers\n" +
1148 "1 USA 214,809,000[16]\n" +
1149 "2 UK 58,200,000[17]\n" +
1150 "3 Canada 17,694,830[18]\n" +
1151 "4 Australia 15,013,965[19]\n" +
1152 "5 Ireland 4,200,000+ (Approx)[17]\n" +
1153 "6 South Africa 3,673,203[20]\n" +
1154 "7 New Zealand 3,500,000+ (Approx)[21]\n" +
1155 "8 Singapore 665,087[24]\n" +
1156 "\n" +
1157 …d Kingdom, the U.S. Virgin Islands, and the United States (various forms of American English).\n" +
1158 "\n" +
1159 …t territories of the United Kingdom and the United States, such as in Hong Kong and Mauritius.\n" +
1160 "\n" +
1161 …icial languages, English has been given official status by 30 of the 50 state governments.[27]\n" +
1162 "\n" +
1163 "English as a global language\n" +
1164 "\n" +
1165 " See also: English on the Internet and global language\n" +
1166 "\n" +
1167 … and most international athletic organisations, including the International Olympic Committee.\n" +
1168 "\n" +
1169 …rmany (51%). [29] Norway and Iceland also have a large majority of competent English-speakers.\n" +
1170 "\n" +
1171 …ten in English, even though only half of them came from authors in English-speaking countries.\n" +
1172 "\n" +
1173 "Dialects and regional varieties\n" +
1174 "\n" +
1175 " Main article: List of dialects of the English language\n" +
1176 "\n" +
1177 …glish has developed a host of English dialects and English-based creole languages and pidgins.\n" +
1178 "\n" +
1179 …umber of accents considered to be more prestigious, such as Received Pronunciation in Britain.\n" +
1180 "\n" +
1181 …xis of the traditional forms differ, sometimes substantially, from other varieties of English.\n" +
1182 "\n" +
1183 …istinctive characteristics of regional dialects, see List of dialects of the English language.\n" +
1184 "\n" +
1185 …ther variant, spoken in the border bilingual regions of Québec in Canada, is called FrEnglish.\n" +
1186 "\n" +
1187 "Constructed varieties of English\n" +
1188 "\n" +
1189 …. Some English schools in Asia teach it as a practical subset of English for use by beginners.\n" +
1190 …fied version of English used by the Voice of America. It uses a vocabulary of only 1500 words.\n" +
1191 " * English reform is an attempt to improve collectively upon the English language.\n" +
1192 …nd communication in specific areas. There is also a tunnelspeak for use in the Channel Tunnel.\n" +
1193 …lish are concepts of standardising English for use as a second language in continental Europe.\n" +
1194 …an Sign Language used in Anglophone countries, which are independent and not based on English.\n" +
1195 " * E-Prime excludes forms of the verb to be.\n" +
1196 "\n" +
1197 …-English was parodied when English was \"made\" one of the constituent languages of Europanto.\n" +
1198 "\n" +
1199 "Phonology\n" +
1200 "\n" +
1201 " Main article: English phonology\n" +
1202 "\n" +
1203 "Vowels\n" +
1204 "IPA Description word\n" +
1205 "monophthongs\n" +
1206 "i/iː Close front unrounded vowel bead\n" +
1207 "ɪ Near-close near-front unrounded vowel bid\n" +
1208 "ɛ Open-mid front unrounded vowel bed\n" +
1209 "æ Near-open front unrounded vowel bad\n" +
1210 "ɒ Open back rounded vowel bod 1\n" +
1211 "ɔ Open-mid back rounded vowel pawed 2\n" +
1212 "ɑ/ɑː Open back unrounded vowel bra\n" +
1213 "ʊ Near-close near-back rounded vowel good\n" +
1214 "u/uː Close back rounded vowel booed\n" +
1215 "ʌ/ɐ Open-mid back unrounded vowel, Near-open central vowel bud\n" +
1216 "ɝ/ɜː Open-mid central unrounded vowel bird 3\n" +
1217 "ə Schwa Rosa's 4\n" +
1218 "ɨ Close central unrounded vowel roses 5\n" +
1219 "diphthongs\n" +
1220 "e(ɪ)/eɪ Close-mid front unrounded vowel\n" +
1221 "Close front unrounded vowel bayed 6\n" +
1222 "o(ʊ)/əʊ Close-mid back rounded vowel\n" +
1223 "Near-close near-back rounded vowel bode 6\n" +
1224 "aɪ Open front unrounded vowel\n" +
1225 "Near-close near-front unrounded vowel cry\n" +
1226 "aʊ Open front unrounded vowel\n" +
1227 "Near-close near-back rounded vowel bough\n" +
1228 "ɔɪ Open-mid back rounded vowel\n" +
1229 "Close front unrounded vowel boy\n" +
1230 "ʊɝ/ʊə Near-close near-back rounded vowel\n" +
1231 "Schwa boor 9\n" +
1232 "ɛɝ/ɛə Open-mid front unrounded vowel\n" +
1233 "Schwa fair 10\n" +
1234 "\n" +
1235 "Notes:\n" +
1236 "\n" +
1237 "It is the vowels that differ most from region to region.\n" +
1238 "\n" +
1239 …h, General American accent; the second corresponds to British English, Received Pronunciation.\n" +
1240 "\n" +
1241 " 1. American English lacks this sound; words with this sound are pronounced with /ɑ/ or /ɔ/.\n" +
1242 " 2. Many dialects of North American English do not have this vowel. See Cot-caught merger.\n" +
1243 " 3. The North American variation of this sound is a rhotic vowel.\n" +
1244 … For them, roses and Rosa's are pronounced the same, and the symbol usually used is schwa /ə/.\n" +
1245 " 5. This sound is often transcribed with /i/ or with /ɪ/.\n" +
1246 …phthongs /eɪ/ and /oʊ/ are monophthongal for many General American speakers, as /eː/ and /oː/.\n" +
1247 …/ turn to /tʃɚ/, /dʒɚ/, /ʃɚ/ and /ʒɚ/ respectively, as in nature, verdure, sure, and treasure.\n" +
1248 …e coda of a syllable. Before the Great Vowel Shift, vowel length was phonemically contrastive.\n" +
1249 …otic accents. In some accents, this sound may be, instead of /ʊə/, /ɔ:/. See pour-poor merger.\n" +
1250 …s, the schwa offglide of /ɛə/ may be dropped, monophthising and lengthening the sound to /ɛ:/.\n" +
1251 "\n" +
1252 "See also\n" +
1253 "\n" +
1254 " * International Phonetic Alphabet for English for more vowel charts.\n" +
1255 "\n" +
1256 "Consonants\n" +
1257 "\n" +
1258 …s the English Consonantal System using symbols from the International Phonetic Alphabet (IPA).\n" +
1259 " bilabial labio-\n" +
1260 "dental dental alveolar post-\n" +
1261 "alveolar palatal velar glottal\n" +
1262 "plosive p b t d k ɡ \n" +
1263 "nasal m n ŋ 1 \n" +
1264 "flap ɾ 2 \n" +
1265 "fricative f v θ ð 3 s z ʃ ʒ 4 ç 5 x 6 h\n" +
1266 "affricate tʃ dʒ 4 \n" +
1267 "approximant ɹ 4 j \n" +
1268 "lateral approximant l \n" +
1269 " labial-velar\n" +
1270 "approximant ʍ w 7\n" +
1271 "\n" +
1272 …n/ in some northerly British accents, appearing only before /k/ and /g/. In all other dialects it …
1273 … it replaces /ɹ/. This is the same sound represented by single r in most varieties of Spanish.\n" +
1274 …ecome the corresponding dental plosives, which then contrast with the usual alveolar plosives.\n" +
1275 …approximant /ɻ/, whereas the same is realized in Scottish English, etc. as the alveolar trill.\n" +
1276 …owever, in some accents (see this), the /j/ is dropped, but the initial consonant is the same.\n" +
1277 … correctly when learning a foreign language. Most speakers use the sounds [k] and [h] instead.\n" +
1278 …In most other dialects it is merged with /w/, in some dialects of Scots it is merged with /f/.\n" +
1279 "\n" +
1280 "Voicing and aspiration\n" +
1281 "\n" +
1282 …top consonants in English depend on dialect and context, but a few general rules can be given:\n" +
1283 "\n" +
1284 …gin a stressed syllable — compare pin [pʰɪn] and spin [spɪn], crap [kʰɹ̥æp] and scrap [skɹæp].\n" +
1285 " o In some dialects, aspiration extends to unstressed syllables as well.\n" +
1286 … o In other dialects, such as Indo-Pakistani English, all voiceless stops remain unaspirated.\n" +
1287 " * Word-initial voiced plosives may be devoiced in some dialects.\n" +
1288 … some dialects (e.g. many varieties of American English) — examples: tap [tʰæp̚], sack [sæk̚].\n" +
1289 …alects they are fully voiced in final position, but only partially voiced in initial position.\n" +
1290 "\n" +
1291 "Supra-segmental features\n" +
1292 "\n" +
1293 "Tone groups\n" +
1294 "\n" +
1295 …ctically, for example, to convey surprise and irony, or to change a statement into a question.\n" +
1296 "\n" +
1297 …ngth, more often being on average five words long or lasting roughly two seconds. For example:\n" +
1298 "\n" +
1299 " - /duː juː niːd ˈɛnɪˌθɪŋ/ Do you need anything?\n" +
1300 " - /aɪ dəʊnt | nəʊ/ I don't, no\n" +
1301 …in fast or colloquial speech that de-emphasises the pause between don't and know even further)\n" +
1302 "\n" +
1303 "Characteristics of intonation\n" +
1304 "\n" +
1305 …e, the first syllable is accentuated; but if it is a verb, the second syllable is accentuated.\n" +
1306 "\n" +
1307 …rong) or unstressed (weak). The stressed syllable is called the nuclear syllable. For example:\n" +
1308 "\n" +
1309 " That | was | the | best | thing | you | could | have | done!\n" +
1310 "\n" +
1311 …and done, which are stressed. Best is stressed harder and, therefore, is the nuclear syllable.\n" +
1312 "\n" +
1313 "The nuclear syllable carries the main point the speaker wishes to make. For example:\n" +
1314 "\n" +
1315 " John hadn't stolen that money. (... Someone else had.)\n" +
1316 …hn hadn't stolen that money. (... You said he had. or ... Not at that time, but later he did.)\n" +
1317 " John hadn't stolen that money. (... He acquired the money by some other means.)\n" +
1318 " John hadn't stolen that money. (... He had stolen some other money.)\n" +
1319 " John hadn't stolen that money. (... He stole something else.)\n" +
1320 "\n" +
1321 "Also\n" +
1322 "\n" +
1323 " I didn't tell her that. (... Someone else told her.)\n" +
1324 " I didn't tell her that. (... You said I did. or ... But now I will!)\n" +
1325 " I didn't tell her that. (... I didn't say it; she could have inferred it, etc.)\n" +
1326 " I didn't tell her that. (... I told someone else.)\n" +
1327 " I didn't tell her that. (... I told her something else.)\n" +
1328 "\n" +
1329 "This can also be used to express emotion:\n" +
1330 "\n" +
1331 " Oh really? (...I didn't know that)\n" +
1332 " Oh really? (...I disbelieve you)\n" +
1333 "\n" +
1334 … means \"polarity unknown\". This underlies the rising pitch of yes/no questions. For example:\n" +
1335 "\n" +
1336 " When do you want to be paid?\n" +
1337 …this case, it denotes a question: \"Can I be paid now?\" or \"Do you desire to be paid now?\")\n" +
1338 " Now. (Falling pitch. In this case, it denotes a statement: \"I choose to be paid now.\")\n" +
1339 "\n" +
1340 "Grammar\n" +
1341 "\n" +
1342 " Main article: English grammar\n" +
1343 "\n" +
1344 …ern English, and the remnants of inflection (such as plural marking) have become more regular.\n" +
1345 "\n" +
1346 … constructions such as questions, negative polarity, the passive voice and progressive tenses.\n" +
1347 "\n" +
1348 "Vocabulary\n" +
1349 "\n" +
1350 "The English vocabulary has changed considerably over the centuries.[31]\n" +
1351 "\n" +
1352 …the English Language\" is critical of this, as well as other perceived abuses of the language.\n" +
1353 "\n" +
1354 …reater control over their linguistic register. See: List of Germanic and Latinate equivalents.\n" +
1355 "\n" +
1356 …nch-speaking elite were the consumers of the meat, produced by English-speaking lower classes.\n" +
1357 "\n" +
1358 …ce, the words mountain, valley, river, aunt, uncle, move, use, push and stay are all Latinate.\n" +
1359 "\n" +
1360 …to be made between formal forms of English and contemporary usage. See also: sociolinguistics.\n" +
1361 "\n" +
1362 "Number of words in English\n" +
1363 "\n" +
1364 …w words. As the General Explanations at the beginning of the Oxford English Dictionary states:\n" +
1365 "\n" +
1366 …the circle of the English language has a well-defined centre but no discernible circumference.\n" +
1367 "\n" +
1368 …Archaic, dialectal, and regional words might or might not be widely considered as \"English\".\n" +
1369 "\n" +
1370 …ry, 2nd edition (OED2) includes over 600,000 definitions, following a rather inclusive policy:\n" +
1371 "\n" +
1372 …ocabulary, and a large measure of dialectal usage and slang (Supplement to the OED, 1933).[32]\n" +
1373 "\n" +
1374 … much higher. It is estimated that about 25,000 words are added to the language each year.[33]\n" +
1375 "\n" +
1376 "Word origins\n" +
1377 "Influences in English vocabulary\n" +
1378 "Influences in English vocabulary\n" +
1379 "\n" +
1380 " Main article: Lists of English words of international origin\n" +
1381 "\n" +
1382 …e \"Latinate\" (Latin-derived, either directly from Norman French or other Romance languages).\n" +
1383 "\n" +
1384 …ins of English vocabulary. None, as yet, are considered definitive by a majority of linguists.\n" +
1385 "\n" +
1386 …inkenstaedt and Dieter Wolff (1973)[34] that estimated the origin of English words as follows:\n" +
1387 "\n" +
1388 " * Langue d'oïl, including French and Old Norman: 28.3%\n" +
1389 " * Latin, including modern scientific and technical Latin: 28.24%\n" +
1390 " * Other Germanic languages (including words directly inherited from Old English): 25%\n" +
1391 " * Greek: 5.32%\n" +
1392 " * No etymology given: 4.03%\n" +
1393 " * Derived from proper names: 3.28%\n" +
1394 " * All other languages contributed less than 1% (e.g. Arabic-English loanwords)\n" +
1395 "\n" +
1396 … of 10,000 words taken from several thousand business letters[35] gave this set of statistics:\n" +
1397 "\n" +
1398 " * French (langue d'oïl), 41%\n" +
1399 " * \"Native\" English, 33%\n" +
1400 " * Latin, 15%\n" +
1401 " * Danish, 2%\n" +
1402 " * Dutch, 1%\n" +
1403 " * Other, 10%\n" +
1404 "\n" +
1405 "However, 83% of the 1,000 most-common English words are Anglo-Saxon in origin. [36]\n" +
1406 "\n" +
1407 "Dutch origins\n" +
1408 "\n" +
1409 " Main article: List of English words of Dutch origin\n" +
1410 "\n" +
1411 …es on the water are often from Dutch origin. Yacht (Jacht) and cruiser (kruiser) are examples.\n" +
1412 "\n" +
1413 "French origins\n" +
1414 "\n" +
1415 " Main article: List of French phrases used by English speakers\n" +
1416 "\n" +
1417 …man spoken by the upper classes in England for several hundred years after the Norman Conquest.\n";
1421 "Ελλάδα\n" +
1422 "Από τη Βικιπαίδεια, την ελεύθερη εγκυκλοπαίδεια\n" +
1423 "Ελληνική Δημοκρατία\n" +
1424 " \n" +
1425 "Σημαία Εθνόσημο\n" +
1426 "Εθνικό σύνθημα: Ελευθερία ή Θάνατος\n" +
1427 "Εθνικός ύμνος: Ὕμνος εἰς τὴν Ἐλευθερίαν\n" +
1428 "\n" +
1429 "Πρωτεύουσα Αθήνα \n" +
1430 "38.01.36N 23.44.00E\n" +
1431 "\n" +
1432 "Μεγαλύτερη πόλη Αθήνα\n" +
1433 "Επίσημες γλώσσες Ελληνική\n" +
1434 "Πολίτευμα\n" +
1435 "\n" +
1436 "Πρόεδρος της Δημοκρατίας\n" +
1437 "Πρωθυπουργός Προεδρευόμενη\n" +
1438 "Κοινοβουλευτική Δημοκρατία\n" +
1439 "Κάρολος Παπούλιας\n" +
1440 "Κωνσταντίνος Καραμανλής\n" +
1441 "Ανεξαρτησία\n" +
1442 "- Κηρύχθηκε\n" +
1443 "- Αναγνωρίστηκε\n" +
1444 "\n" +
1445 "25 Μαρτίου, 1821\n" +
1446 "1828\n" +
1447 "Έκταση\n" +
1448 " - Σύνολο\n" +
1449 " - Νερό (%) \n" +
1450 "131.940 km² (94ηη)\n" +
1451 "%0.86\n" +
1452 "Πληθυσμός\n" +
1453 " - Εκτίμηση 2006\n" +
1454 " - Απογραφή 2001\n" +
1455 " - Πυκνότητα \n" +
1456 "11.120.000 [1] (72ηη)\n" +
1457 "10.964.020\n" +
1458 "83.1 κάτ./km² (87ηη)\n" +
1459 "Α.Ε.Π.\n" +
1460 " - Ολικό\n" +
1461 " - Κατά κεφαλή Εκτίμηση 2007\n" +
1462 "$305,595 δισ. (37η)\n" +
1463 "$27,360 (27η)\n" +
1464 "Νόμισμα Ευρώ\n" +
1465 "(€)\n" +
1466 "Ζώνη ώρας\n" +
1467 " - Θερινή ώρα (UTC+2)\n" +
1468 "(UTC+3)\n" +
1469 "Internet TLD .gr\n" +
1470 "Κωδικός κλήσης +30\n" +
1471 …μακρά και πλούσια ιστορία κατά την οποία άσκησε μεγάλη πολιτισμική επίδραση σε τρεις ηπείρους.\n" +
1472 "Πίνακας περιεχομένων [Απόκρυψη]\n" +
1473 "1 Ιστορία\n" +
1474 "2 Πολιτικά\n" +
1475 "2.1 Κόμματα\n" +
1476 "2.2 Κυβέρνηση\n" +
1477 "3 Περιφέρειες\n" +
1478 "3.1 Βουνά της Ελλάδας\n" +
1479 "3.2 Λίμνες της Ελλάδας\n" +
1480 "3.3 Ποτάμια της Ελλάδας\n" +
1481 "3.4 Κλίμα\n" +
1482 "4 Οικονομία\n" +
1483 "5 Δημογραφία\n" +
1484 "6 Ένοπλες δυνάμεις και Σώματα ασφαλείας\n" +
1485 "6.1 Υποχρεωτική στράτευση\n" +
1486 "7 Πολιτισμός\n" +
1487 "7.1 Αργίες\n" +
1488 "8 Σημειώσεις\n" +
1489 "9 Δείτε επίσης\n" +
1490 "10 Εξωτερικές συνδέσεις\n" +
1491 "[Επεξεργασία]\n" +
1492 "Ιστορία\n" +
1493 "\n" +
1494 "Κύριο άρθρο: Ελληνική ιστορία\n" +
1495 …σιογνωμία της Βυζαντινής Αυτοκρατορίας και αργότερα θα πυροδοτήσει την Αναγέννηση στην Ευρώπη.\n" +
1496 …α της Οθωμανικής Αυτοκρατορίας. Σταδιακά το Βυζάντιο κατακτήθηκε ολόκληρο μέσα στον 15ο αιώνα.\n" +
1497 …μέρει, επεκτείνοντας σταδιακά την έκτασή της, μέχρι να φτάσει το σημερινό της μέγεθος το 1947.\n" +
1498 …ς της Ευρωπαϊκής Οικονομικής και Νομισματικής Ένωσης (ΟΝΕ) γνωστής και ως ζώνης ευρώ, το 2001.\n" +
1499 "Ελληνική ιστορία \n" +
1500 "Κυκλαδικός πολιτισμός (3η χιλιετία π.Χ.)\n" +
1501 "Μινωικός πολιτισμός (3000-1450 π.Χ.)\n" +
1502 "Μυκηναϊκός πολιτισμός (1600-1100 π.Χ.)\n" +
1503 "Γεωμετρική εποχή (1100-800 π.Χ.)\n" +
1504 "Αρχαϊκή εποχή (800-500 π.Χ.)\n" +
1505 "Κλασική εποχή (500 π.Χ.- 323 π.Χ.)\n" +
1506 "Ελληνιστική εποχή (323-146 π.Χ.)\n" +
1507 "Ρωμαϊκή περίοδος (146 π.Χ.-330 μ.Χ.)\n" +
1508 "Βυζαντινή περίοδος (330-1453)\n" +
1509 "Οθωμανική περίοδος (1453-1821)\n" +
1510 "Νεότερη Ελλάδα (1821 έως σήμερα)\n" +
1511 "Σχετικά\n" +
1512 "Αρχαία ελληνική γραμματεία\n" +
1513 "Ελληνική γλώσσα\n" +
1514 "Ονομασίες Ελλήνων\n" +
1515 "\n" +
1516 "[Επεξεργασία]\n" +
1517 "Πολιτικά\n" +
1518 "\n" +
1519 …καιωμάτων. Η Ελλάδα είναι επίσης μέλος της Ευρωπαϊκής Σύμβασης για τα Δικαιώματα του Ανθρώπου.\n" +
1520 … η Κυβέρνηση, ενώ η δικαστική εξουσία ασκείται από τα δικαστήρια στο όνομα του ελληνικού λαού.\n" +
1521 …ρίας της Δημοκρατίας. Η θητεία του είναι πενταετής με δικαίωμα επανεκλογής για μία ακόμη φορά.\n" +
1522 …4 βουλευτικές εκλογές, το πρώτο κόμμα εξασφαλίζει απόλυτη πλειοψηφία στη Βουλή με ποσοστό 41%.\n" +
1523 …ριεχομένου. Οι Π.Ν.Π. έχουν ισχύ νόμου και οφείλουν να εγκριθούν εντός 40 ημερών από τη Βουλή.\n" +
1524 …νητικής πολιτικής μέσα στο πλαίσιο των νόμων\" [3]. Οι βασικότερες εξουσίες του είναι οι εξής:\n" +
1525 "Προεδρεύει του Υπουργικού Συμβουλίου, στο οποίο μετέχει μαζί με τους Υπουργούς.\n" +
1526 …ται και παύονται από τον Πρόεδρο της Δημοκρατίας οι υπουργοί και οι υφυπουργοί της Κυβέρνησης.\n" +
1527 "Καθορίζει με τον οικείο Υπουργό τις αρμοδιότητες των υφυπουργών.\n" +
1528 …ης Κυβερνήσεως, της Κεντρικής Νομοπαρασκευαστικής Επιτροπής και της Γενικής Γραμματείας Τύπου.\n" +
1529 …φημερίδα της Κυβερνήσεως οποιουδήποτε κειμένου πρέπει, κατά το νόμο, να καταχωρισθεί σε αυτήν.\n" +
1530 "[Επεξεργασία]\n" +
1531 "Κόμματα\n" +
1532 "Περισσότερα: Κατάλογος ελληνικών πολιτικών κομμάτων\n" +
1533 … Άλλα κόμματα είναι το Κομμουνιστικό Κόμμα Ελλάδας, ο Συνασπισμός της Αριστεράς και ο ΛΑ.Ο.Σ..\n" +
1534 "[Επεξεργασία]\n" +
1535 "Κυβέρνηση\n" +
1536 "Περισσότερα: Κυβέρνηση της Ελλάδας\n" +
1537 …εξασφάλισε το 5.04% και 14 έδρες και τέλος το ΛΑ.Ο.Σ εξασφάλισε το 3.80% κερδίζοντας 10 έδρες.\n" +
1538 "[Επεξεργασία]\n" +
1539 "Περιφέρειες\n" +
1540 "\n" +
1541 "Κύριο άρθρο: Περιφέρειες της Ελλάδας\n" +
1542 … σε 13 διοικητικές περιοχές γνωστές σαν Περιφέρειες, που διαχωρίζονται περαιτέρω σε 51 Νομούς:\n" +
1543 "Αττική\n" +
1544 "Αττική\n" +
1545 "Στερεά Ελλάδα\n" +
1546 "Εύβοια\n" +
1547 "Ευρυτανία\n" +
1548 "Φωκίδα\n" +
1549 "Φθιώτιδα\n" +
1550 "Βοιωτία\n" +
1551 "Κεντρική Μακεδονία\n" +
1552 "Χαλκιδική\n" +
1553 "Ημαθία\n" +
1554 "Κιλκίς\n" +
1555 "Πέλλα\n" +
1556 "Πιερία\n" +
1557 "Σέρρες\n" +
1558 "Θεσσαλονίκη\n" +
1559 "Κρήτη\n" +
1560 "Χανιά\n" +
1561 "Ηράκλειο\n" +
1562 "Λασίθι\n" +
1563 "Ρέθυμνο\n" +
1564 "Ανατολική Μακεδονία και Θράκη\n" +
1565 "Καβάλα\n" +
1566 "Δράμα\n" +
1567 "Ξάνθη\n" +
1568 "Ροδόπη\n" +
1569 "Έβρος\n" +
1570 "Ήπειρος\n" +
1571 "Άρτα\n" +
1572 "Ιωάννινα\n" +
1573 "Πρέβεζα\n" +
1574 "Θεσπρωτία\n" +
1575 "Ιόνια νησιά\n" +
1576 "Κέρκυρα\n" +
1577 "Κεφαλονιά\n" +
1578 "Λευκάδα\n" +
1579 "Ζάκυνθος\n" +
1580 "Βόρειο Αιγαίο\n" +
1581 "Χίος\n" +
1582 "Λέσβος\n" +
1583 "Σάμος - Ικαρία\n" +
1584 "Πελοπόννησος\n" +
1585 "Αρκαδία\n" +
1586 "Αργολίδα\n" +
1587 "Κορινθία\n" +
1588 "Λακωνία\n" +
1589 "Μεσσηνία\n" +
1590 "Νότιο Αιγαίο\n" +
1591 "Κυκλάδες\n" +
1592 "Δωδεκάνησα\n" +
1593 "Θεσσαλία\n" +
1594 "Καρδίτσα\n" +
1595 "Λάρισα\n" +
1596 "Μαγνησία\n" +
1597 "Τρίκαλα\n" +
1598 "Δυτική Ελλάδα\n" +
1599 "Αχαΐα\n" +
1600 "Αιτωλοακαρνανία\n" +
1601 "Ηλεία\n" +
1602 "Δυτική Μακεδονία\n" +
1603 "Φλώρινα\n" +
1604 "Γρεβενά\n" +
1605 "Καστοριά\n" +
1606 "Κοζάνη\n" +
1607 …μοί τοπικής αυτοδιοίκησης: 361 δήμοι και 5.560 κοινότητες, υποδιαιρούμενες σε 12.817 οικισμούς\n" +
1608 "\n" +
1609 "\n" +
1610 "\n" +
1611 "Αλβανία\n" +
1612 "\n" +
1613 "П.Γ.Δ.Μ.\n" +
1614 "\n" +
1615 "Βουλγαρία\n" +
1616 "'\n" +
1617 "\n" +
1618 "Τουρκία\n" +
1619 "\n" +
1620 "EΛΛAΣ\n" +
1621 "AΘHNA\n" +
1622 "Θεσσαλονίκη\n" +
1623 "Καβάλα\n" +
1624 "Αλεξανδρούπολη\n" +
1625 "Κέρκυρα\n" +
1626 "Ηγουμενίτσα\n" +
1627 "Λάρισα\n" +
1628 "Βόλος\n" +
1629 "Ιωάννινα\n" +
1630 "Χαλκίδα\n" +
1631 "Πάτρα\n" +
1632 "Πειραιάς\n" +
1633 "Ελευσίνα\n" +
1634 "Λαύριο\n" +
1635 "Ηράκλειο\n" +
1636 "Μ α κ ε δ ο ν ί α\n" +
1637 "Θράκη\n" +
1638 "Ήπειρος\n" +
1639 "Θεσσαλία\n" +
1640 "Στερεά Ελλάδα\n" +
1641 "Πελοπόννησος\n" +
1642 "Όλυμπος (2917m)\n" +
1643 "Λευκάδα\n" +
1644 "Κεφαλονιά\n" +
1645 "Λήμνος\n" +
1646 "Λέσβος\n" +
1647 "Χίος\n" +
1648 "Σάμος\n" +
1649 "Τήνος\n" +
1650 "Ικαρία\n" +
1651 "Νάξος\n" +
1652 "Σαντορίνη\n" +
1653 "Κως\n" +
1654 "Ρόδος\n" +
1655 "Κάρπαθος\n" +
1656 "Κύθηρα\n" +
1657 "Γαύδος\n" +
1658 "Αιγαίον\n" +
1659 "Πέλαγος\n" +
1660 "Μυρτώον\n" +
1661 "Πέλαγος\n" +
1662 "Κρητικόν Πέλαγος\n" +
1663 "Ιόνιον\n" +
1664 "Πέλαγος\n" +
1665 "Μεσόγειος\n" +
1666 "Θάλασσα\n" +
1667 "Κρήτη\n" +
1668 "[Επεξεργασία]\n" +
1669 "Βουνά της Ελλάδας\n" +
1670 "Κύριο άρθρο: Κατάλογος βουνών της Ελλάδας\n" +
1671 …ή λοφώδες. Μεγάλο μέρος του είναι ξηρό και βραχώδες, μόνο 28% του εδάφους είναι καλλιεργήσιμο.\n" +
1672 "Όλυμπος 2917 μ. Θεσσαλία, Κεντρική Μακεδονία (Λάρισα, Πιερία)\n" +
1673 "Σμόλικας 2637 μ. Βόρεια Πίνδος (Ιωάννινα)\n" +
1674 "Βόρας 2524 μ. Κεντρική Μακεδονία (Πέλλα, Φλώρινα, Π.Γ.Δ.Μ.)\n" +
1675 "Γράμος 2520 μ. Δυτική Μακεδονία (Καστοριά, Ιωάννινα, Αλβανία)\n" +
1676 "Γκιώνα 2510 μ. Στερεά (Φωκίδα)\n" +
1677 "Τύμφη 2497 μ. Βόρεια Πίνδος (Ιωάννινα)\n" +
1678 "Βαρδούσια 2495 μ. Στερεά (Φωκίδα)\n" +
1679 "Αθαμανικά όρη 2469 μ. Νότια Πίνδος (Άρτα)\n" +
1680 "Παρνασσός 2457 μ. Στερεά (Φωκίδα, Φθιώτιδα)\n" +
1681 "Ψηλορείτης 2456 μ. Κρήτη (Ηράκλειο)\n" +
1682 "\n" +
1683 "\n" +
1684 "\n" +
1685 "\n" +
1686 …ων νησιών, τα οποία είναι πάνω από 1500. Έχει μήκος συνόρων που πλησιάζει τα 1.181 χιλιόμετρα.\n" +
1687 "\n" +
1688 "\n" +
1689 "Δορυφορική εικόνα της Ελλάδας\n" +
1690 "Κύριο άρθρο: Γεωγραφία της Ελλάδας\n" +
1691 "[Επεξεργασία]\n" +
1692 "Λίμνες της Ελλάδας\n" +
1693 "Κύριο άρθρο: Κατάλογος λιμνών της Ελλάδας\n" +
1694 …ίων βρίσκονται στο ηπειρωτικό της τμήμα. Οι μεγαλύτερες λίμνες στην ελληνική επικράτεια είναι:\n" +
1695 "Τριχωνίδα 96.513 τ.χλμ.\n" +
1696 "Βόλβη 75.600 τ.χλμ\n" +
1697 "Λίμνη Βεγορίτιδα 72.488 τ.χλμ\n" +
1698 "Λίμνη Βιστονίδα 45.625 τ.χλμ\n" +
1699 "Λίμνη Κορώνεια 42.823 τ.χλμ\n" +
1700 "Μικρή Πρέσπα (ελληνικό τμήμα) 43.122 τ.χλμ\n" +
1701 "Μεγάλη Πρέσπα (ελληνικό τμήμα) 38.325 τ.χλμ\n" +
1702 "Κερκίνη 37.688 τ.χλμ\n" +
1703 …εκτρικού ρεύματος, όπως η Λίμνη Κρεμαστών (68.531 τ.χλμ) και η Λίμνη Πολυφύτου (56.793 τ.χλμ).\n" +
1704 "\n" +
1705 "[Επεξεργασία]\n" +
1706 "Ποτάμια της Ελλάδας\n" +
1707 …πή του Αχελώου από τη νότια Πίνδο για την αντιμετώπιση του υδατικού προβλήματος της Θεσσαλίας.\n" +
1708 …οταμών της Ελλάδας. Το μήκος που αναγράφεται είναι αυτό που διατρέχει την ελληνική επικράτεια.\n" +
1709 "Αλιάκμονας 297 χλμ.\n" +
1710 "Αχελώος 220 χλμ.\n" +
1711 "Πηνειός (Θεσσαλίας) 205 χλμ.\n" +
1712 "Έβρος [4] 204 χλμ.\n" +
1713 "Νέστος [4] 130 χλμ.\n" +
1714 "Στρυμόνας [4] 118 χλμ.\n" +
1715 "Θύαμις (Καλαμάς) 115 χλμ.\n" +
1716 "Αλφειός 110 χλμ.\n" +
1717 "Άραχθος 110 χλμ.\n" +
1718 "[Επεξεργασία]\n" +
1719 "Κλίμα\n" +
1720 … ζεστά ξηρά καλοκαίρια. Το κλίμα της χώρας μπορεί να διαιρεθεί σε τέσσερις βασικές κατηγορίες:\n" +
1721 …υψόμετρο περίπου >1500μ στη βόρεια Ελλάδα, >1800μ στην κεντρική Ελλάδα και >2000μ στην Κρήτη).\n" +
1722 …ναι κοινότεροι τον Ιούλιο και τον Αύγουστο. Σπάνια, πάντως, διαρκούν περισσότερες από 3 μέρες.\n" +
1723 … σε μικρή απόσταση μεταξύ τους, πράγμα που παρουσιάζεται σε λίγες μόνο χώρες σε όλο τον κόσμο.\n" +
1724 … το τέλος Μαρτίου και τη θερμή και άνομβρη εποχή που διαρκεί από τον Απρίλιο έως τον Οκτώβριο.\n" +
1725 …°C στις ηπειρωτικές περιοχές και σε χαμηλότερες τιμές κάτω από το μηδέν στις βόρειες περιοχές.\n" +
1726 …μερο του Φεβρουαρίου από ηλιόλουστες ημέρες, τις γνωστές από την αρχαιότητα Αλκυονίδες ημέρες.\n" +
1727 …εν βρέχει εκτός από σπάνια διαστήματα με ραγδαίες βροχές ή καταιγίδες μικρής γενικά διάρκειας.\n" +
1728 …κτιες περιοχές της χώρας και από τους βόρειους ανέμους (ετησίες) που φυσούν κυρίως στο Αιγαίο.\n" +
1729 …ι μακρύ και θερμό και πολλές φορές παρατείνεται στη νότια Ελλάδα μέχρι τα μισά του Δεκεμβρίου.\n" +
1730 "[Επεξεργασία]\n" +
1731 "Οικονομία\n" +
1732 "\n" +
1733 "Κύριο άρθρο: Οικονομία της Ελλάδας\n" +
1734 … βιομηχανία στην Ελλάδα με έσοδα γύρω στα 12 δισ. ευρώ ήταν η συνήθως σχετικά αφανής ναυτιλία.\n" +
1735 …ική, Νότιο Αιγαίο, Στερεά Ελλάδα, Κεντρική Μακεδονία, Βόρειο Αιγαίο και οριακά η Πελοπόννησος.\n" +
1736 …ι η ελαχιστοποίηση των γραφειοκρατικών αδυναμιών. Η ανάπτυξη υπολογίζεται σε 3,9% για το 2004.\n" +
1737 … της στην Ευρωπαϊκή Κεντρική Τράπεζα (Ε.Κ.Τ.), μετά την είσοδό της στην ζώνη του ευρώ το 2001.\n" +
1738 "[Επεξεργασία]\n" +
1739 "Δημογραφία\n" +
1740 "\n" +
1741 "Κύριο άρθρο: Δημογραφία της Ελλάδας\n" +
1742 "Άρθρο βασικών αποτελεσμάτων απογραφής: Απογραφή 2001\n" +
1743 …ν ημέρα της απογραφής, στη χώρα βρέθηκαν και απογράφηκαν (πραγματικός πληθυσμός) 10.964.020 κ.\n" +
1744 …ανάστες που βρίσκονται στην υπόλοιπη χώρα υπολογίζεται ότι ανέρχονται σε 200.000-300.000.» [6]\n" +
1745 … είναι οι προερχόμενοι από Αλβανία, Ρουμανία, Βουλγαρία, Πακιστάν, Ουκρανία, Πολωνία, Αίγυπτο.\n" +
1746 …κάνια. Οι μεγαλύτερες ομάδες παλιννοστούντων είναι από την Αλβανία, την Ρωσία και την Γεωργία.\n" +
1747 "[Επεξεργασία]\n" +
1748 "Ένοπλες δυνάμεις και Σώματα ασφαλείας\n" +
1749 "\n" +
1750 "Ελληνικές Ένοπλες Δυνάμεις:\n" +
1751 "Ελληνικός Στρατός\n" +
1752 "Ελληνικό Πολεμικό Ναυτικό\n" +
1753 "Ελληνική Πολεμική Αεροπορία\n" +
1754 "Σώματα ασφαλείας:\n" +
1755 "Ελληνική Αστυνομία\n" +
1756 "Πυροσβεστικό Σώμα\n" +
1757 "Λιμενικό Σώμα\n" +
1758 "[Επεξεργασία]\n" +
1759 "Υποχρεωτική στράτευση\n" +
1760 "Κύριο άρθρο: Η θητεία στην Ελλάδα\n" +
1761 …νες πολίτες να υπερασπιστούν την Ελλάδα, ο φόρτος έγκειται ολοκληρωτικά στον ανδρικό πληθυσμό.\n" +
1762 …ηρωτοί να ζούνε από την οικονομική στήριξη των γονέων τους κατά την διάρκεια της θητείας τους.\n" +
1763 "[Επεξεργασία]\n" +
1764 "Πολιτισμός\n" +
1765 "\n" +
1766 "Κατάλογος διάσημων Ελλήνων\n" +
1767 "Ελληνική μυθολογία\n" +
1768 "Αρχαία ελληνική λογοτεχνία\n" +
1769 "Ελληνική Αρχιτεκτονική\n" +
1770 "Ελληνική κουζίνα\n" +
1771 "Ελληνική Γλώσσα\n" +
1772 "Ελληνική Μουσική\n" +
1773 "Ελληνικά Μουσεία\n" +
1774 "Μέσα Ενημέρωσης\n" +
1775 "[Επεξεργασία]\n" +
1776 "Αργίες\n" +
1777 "Ημερομηνία Ονομασία Σχόλια\n" +
1778 "1 Ιανουαρίου Πρωτοχρονιά \n" +
1779 "6 Ιανουαρίου Θεοφάνεια \n" +
1780 "κινητή Καθαρά Δευτέρα έναρξη της Μεγάλης Τεσσαρακοστής\n" +
1781 "25η Μαρτίου Ευαγγελισμός της Θεοτόκου και Εθνική Εορτή Εθνική Εορτή για την Επανάσταση του 1821\n"…
1782 "κινητή Μεγάλη Παρασκευή \n" +
1783 "κινητή Πάσχα Ανάσταση του Χριστού\n" +
1784 "κινητή Δευτέρα Διακαινησίμου (Δευτέρα του Πάσχα) Δευτέρα μετά την Ανάσταση\n" +
1785 "1 Μαΐου Πρωτομαγιά \n" +
1786 "κινητή Αγίου Πνεύματος \n" +
1787 "15 Αυγούστου Κοίμηση της Θεοτόκου \n" +
1788 "28η Οκτωβρίου Επέτειος του Όχι Εθνική Εορτή (1940)\n" +
1789 "25 Δεκεμβρίου Χριστούγεννα \n" +
1790 "26 Δεκεμβρίου Σύναξις Θεοτόκου \n" +
1791 "[Επεξεργασία]\n" +
1792 "Σημειώσεις\n" +
1793 "\n" +
1794 "↑ www.destatis.de εκτίμηση πληθυσμού χώρας, 2006\n" +
1795 "↑ Σύνταγμα της Ελλάδας, άρθρο 30\n" +
1796 "↑ 3,0 3,1 Σύνταγμα της Ελλάδας, άρθρο 82\n" +
1797 "↑ 4,0 4,1 4,2 Πηγάζει στη Βουλγαρία\n" +
1798 "↑ 5,0 5,1 απογραφή 2001\n" +
1799 …ησκευτικής Ελευθερίας του 2005 στην ελληνική και στην αγγλική, Υπουργείο Εξωτερικών των Η.Π.Α.\n" +
1800 "[Επεξεργασία]\n" +
1801 "Δείτε επίσης\n" +
1802 "\n" +
1803 "Σημαία της Ελλάδας\n" +
1804 "Κατάλογος γλωσσών της Ελλάδας\n" +
1805 "Τράπεζα της Ελλάδος\n" +
1806 "Ονομασίες της Ελλάδας σε διάφορες γλώσσες\n" +
1807 "Άτλας της Ελλάδας: συλλογή διαφόρων χαρτών της Ελλάδας στα Κοινά (Commons).\n" +
1808 "Κατάλογος νοσοκομείων της Ελλάδας\n" +
1809 "[Επεξεργασία]\n" +
1810 "Εξωτερικές συνδέσεις\n" +
1811 "\n" +
1812 "Πρωθυπουργός της Ελλάδας (Γραφείο Πρωθυπουργού)\n" +
1813 "Βουλή των Ελλήνων\n" +
1814 "Παράθυρο στην Ελλάδα (χρήσιμες πληροφορίες και σύνδεσμοι για την Ελλάδα)\n" +
1815 "Παράθυρο στην Ελλάδα (παλαιότερη «έκδοση»)\n" +
1816 "Ελληνικός Οργανισμός Τουρισμού\n" +
1817 "Υπουργείο Εξωτερικών\n";
1821 "היסטוריה של סין\n" +
1822 "מתוך ויקיפדיה, האנציקלופדיה החופשית\n" +
1823 "קפיצה אל: ניווט, חפש\n" +
1824 "\n" +
1825 …התכוונתם לההיסטוריה של מדינה המוכרת היום בשם \"סין\", ראו היסטוריה של הרפובליקה העממית של סין.\n" +
1826 "\n" +
1827 "בערך זה מופיע גופן מזרח אסייתי\n" +
1828 "\n" +
1829 …ה, תצטרכו להתקין גופן מזרח אסייתי במחשבכם. אם אינכם יודעים כיצד לעשות זאת, לחצו כאן לקבלת עזרה\n" +
1830 "\n" +
1831 …ו גם גלי הגירה אל ומחוץ למדינה יצרו יחד את דמותם של התרבות והעם הסיני כפי שהם מוכרים לנו היום.\n" +
1832 "היסטוריה של סין\n" +
1833 "\n" +
1834 " * התקופה הקדומה\n" +
1835 "\n" +
1836 " שלושת המלכים וחמשת הקיסרים\n" +
1837 " שושלת שיה\n" +
1838 " שושלת שאנג\n" +
1839 " שושלת ג'ואו\n" +
1840 " תקופת האביב והסתיו\n" +
1841 " תקופת המדינות הלוחמות\n" +
1842 "\n" +
1843 " * סין הקיסרית\n" +
1844 "\n" +
1845 " שושלת צ'ין\n" +
1846 " שושלת האן המערבית\n" +
1847 " שושלת שין\n" +
1848 " שושלת האן המזרחית\n" +
1849 " שלושת הממלכות\n" +
1850 " שושלת ג'ין\n" +
1851 " השושלת הצפונית והדרומית\n" +
1852 " שושלת סוי\n" +
1853 " שושלת טאנג\n" +
1854 " שושלת סונג\n" +
1855 " שושלת יו'אן\n" +
1856 " שושלת מינג\n" +
1857 " שושלת צ'ינג\n" +
1858 "\n" +
1859 " * התפוררות הקיסרות\n" +
1860 "\n" +
1861 " מלחמת האופיום הראשונה\n" +
1862 " מרד טאיפינג\n" +
1863 " מלחמת האופיום השנייה\n" +
1864 " מלחמת סין-צרפת\n" +
1865 " מלחמת סין-יפן הראשונה\n" +
1866 " רפורמת מאה הימים\n" +
1867 " מרד הבוקסרים\n" +
1868 "\n" +
1869 " * סין המודרנית\n" +
1870 "\n" +
1871 " מהפכת שינהאי\n" +
1872 " הקמתה של המפלגה הקומניסטית של סין\n" +
1873 " המצעד הארוך\n" +
1874 " תקרית שיאן\n" +
1875 " מלחמת סין-יפן השנייה\n" +
1876 " מלחמת האזרחים הסינית\n" +
1877 "\n" +
1878 " * העת החדשה\n" +
1879 "\n" +
1880 " הקמת הרפובליקה העממית של סין\n" +
1881 " מערכת מאה הפרחים\n" +
1882 " הזינוק הגדול קדימה\n" +
1883 " הפיצול הסיני-סובייטי\n" +
1884 " מלחמת הודו-סין\n" +
1885 " מהפכת התרבות בסין\n" +
1886 " תקרית טיאנאנמן\n" +
1887 "\n" +
1888 "ראו גם\n" +
1889 "\n" +
1890 " * הרפובליקה הסינית\n" +
1891 " * לוח זמנים של ההיסטוריה של סין\n" +
1892 "\n" +
1893 "פורטל סין\n" +
1894 "קטגוריה ראשית\n" +
1895 "\n" +
1896 "\n" +
1897 "תוכן עניינים\n" +
1898 "[הסתר]\n" +
1899 "\n" +
1900 " * 1 פרה-היסטוריה\n" +
1901 " o 1.1 שלושת המלכים וחמשת הקיסרים\n" +
1902 " * 2 היסטוריה קדומה\n" +
1903 " o 2.1 שושלת שְׂיָה\n" +
1904 " o 2.2 שושלת שָׁאנְג\n" +
1905 " o 2.3 שושלת ג'וֹאוּ\n" +
1906 " o 2.4 תקופת האביב והסתיו\n" +
1907 " o 2.5 תקופת המדינות הלוחמות\n" +
1908 " * 3 שושלת צ'ין: האימפריה הסינית הראשונה\n" +
1909 " * 4 שושלת האן: תקופה של שגשוג\n" +
1910 " * 5 ג'ין, שש עשרה הממלכות והשושלות הדרומית והצפונית: התקופה האפלה של סין\n" +
1911 " * 6 שושלת טאנג: חזרה לשיגשוג\n" +
1912 " * 7 שושלת סונג ושכנותיה הצפוניות, ליאו וג'ין\n" +
1913 " * 8 המונגולים\n" +
1914 " * 9 תחייתה מחדש של התרבות הסינית\n" +
1915 " * 10 תקופת מינג: מהתפתחות לבידוד\n" +
1916 " * 11 שושלת צ'ינג\n" +
1917 " * 12 הרפובליקה הסינית\n" +
1918 " * 13 הרפובליקה העממית של סין\n" +
1919 " * 14 ראו גם\n" +
1920 " * 15 לקריאה נוספת\n" +
1921 " * 16 קישורים חיצוניים\n" +
1922 " * 17 הערות שוליים\n" +
1923 "\n" +
1924 "[עריכה] פרה-היסטוריה\n" +
1925 "\n" +
1926 …ם צאצאי אותו הומו ארקטוס, אלא צאצאי הומו סאפיינס שהגיע לאזור מאזור אפריקה רק לפני 65,000 שנים.\n" +
1927 "\n" +
1928 …ואגירתו לזמן ממושך יותר, וזו הביאה בהדרגה לגידול האוכלוסייה, להתפתחותה התרבותית ולריבוד חברתי.\n" +
1929 "\n" +
1930 … כאשר ראשוני הכפרים באזור הופיעו שם. מרבית העדויות למרכז חשוב זה נמצאות באזור העיר שי-אן בסין.\n" +
1931 "\n" +
1932 "[עריכה] שלושת המלכים וחמשת הקיסרים\n" +
1933 "\n" +
1934 " ערך מורחב – שלושת המלכים וחמשת הקיסרים\n" +
1935 "\n" +
1936 … מיסטיות והם מתוארים כשליטים נבונים ובעלי מוסר למופת. אחד מהם, הקיסר הצהוב נחשב לאבי בני ההאן.\n" +
1937 "\n" +
1938 …ן לפצוע על שחר ההיסטוריה. מכאן ואילך, עד למאה העשרים, מתוארות תולדות סין לפי השושלות שמשלו בה.\n" +
1939 "\n" +
1940 "[עריכה] היסטוריה קדומה\n" +
1941 "\n" +
1942 "[עריכה] שושלת שְׂיָה\n" +
1943 "\n" +
1944 " ערך מורחב – שושלת שיה\n" +
1945 "\n" +
1946 …והסתיימה בימיו של גְ'יֵה איש שְׂיָה, כך על-פי סְה-מָה צְ'ייֵן ומקורות אחרים מתקופת שושלת צ'ין.\n" +
1947 "\n" +
1948 …ך היו כפופות לה. אורך ימיה של השושלת לא ברור, אך 431 או 471 שנים הן שתי החלופות הסבירות ביותר.\n" +
1949 "\n" +
1950 …כר מעצמות הניחוש של שושלת שאנג ומכלי הברונזה של שושלת ג'ואו, נותר טיבה של שושלת שיה לוט בערפל.\n" +
1951 "\n" +
1952 "[עריכה] שושלת שָׁאנְג\n" +
1953 "\n" +
1954 " ערך מורחב – שושלת שאנג\n" +
1955 "\n" +
1956 …יתה הבירה התשיעית והאחרונה של שושלת שאנג. לשושלת היו 31 מלכים, והיא הייתה הארוכה שבשושלות סין.\n" +
1957 "\n" +
1958 … אניאנג, תוך שהיא מקיימת קשרי מסחר עם יישובים שונים בסביבתה, שהיו שונים זה מזה מבחינה תרבותית.\n" +
1959 "\n" +
1960 "[עריכה] שושלת ג'וֹאוּ\n" +
1961 "\n" +
1962 " ערך מורחב – שושלת ג'ואו\n" +
1963 "\n" +
1964 …יטתם התפרסה אל כל עבר מושבות נהר היאנגטסה. זו הייתה ההגירה הראשונה בגודל כזה מצפון סין לדרומה.\n" +
1965 "\n" +
1966 "[עריכה] תקופת האביב והסתיו\n" +
1967 "\n" +
1968 " ערך מורחב – תקופת האביב והסתיו\n" +
1969 "\n" +
1970 …התקופה לקוח משם הספר רשומות האביב והסתיו, תיעוד היסטורי של אותה תקופה אשר נכתב בידי קונפוציוס.\n" +
1971 "\n" +
1972 …דה את חופש המחשבה וההתפתחות הטכנולוגית. לאחר תקופת האביב והסתיו החלה בסין תקופת מלחמת המדינות.\n" +
1973 "\n" +
1974 "[עריכה] תקופת המדינות הלוחמות\n" +
1975 "\n" +
1976 " ערך מורחב – תקופת המדינות הלוחמות\n" +
1977 "\n" +
1978 …שמה קיבלה התקופה מ\"רשומות המדינות הלוחמות\", תיעוד היסטורי של התקופה, שנכתב בתקופת שושלת האן.\n" +
1979 "\n" +
1980 … הסינית לדוכס), הכפופים כביכול למלך של ג'ואו, לוואנג (王) - מלכים, השווים במעמדם למלך של ג'ואו.\n" +
1981 "\n" +
1982 …תן של פילוסופיות שונות כגון קונפוציזם, דאואיזם, לגאליזם, ומוהיזם למעמד של דתות במדינות השונות.\n" +
1983 "\n" +
1984 …אחר שממלכת צ'ין הצליחה להביס ולכבוש את שאר הממלכות, הפך המלך צ'ין לקיסר הראשון של סין המאוחדת.\n" +
1985 "\n" +
1986 "[עריכה] שושלת צ'ין: האימפריה הסינית הראשונה\n" +
1987 "\n" +
1988 " ערך מורחב – שושלת צ'ין\n" +
1989 "\n" +
1990 …212 לפנה\"ס עלה בידו של צ'ין להשתלט סופית על כל הממלכות בסין העתיקה ולשים קץ למלחמות הפנימיות.\n" +
1991 "\n" +
1992 …שושלת מינג). בניו של הקיסר לא היו מוצלחים כמוהו, ועם מותו של הקיסר תמה תקופת שלטונה של שושלתו.\n" +
1993 "\n" +
1994 …ן בשפה העברית וכן בשפה האנגלית (China), מגיע ככל הנראה מהמילה צ'ין (秦), שמה של השושלת הראשונה.\n" +
1995 "\n" +
1996 "[עריכה] שושלת האן: תקופה של שגשוג\n" +
1997 "\n" +
1998 " ערך מורחב – שושלת האן\n" +
1999 "\n" +
2000 …טחים בהם ישבו שבטים אלו. שטחים חדשים אלו אפשרו לסין לראשונה לפתוח קשר מסחר עם המערב: דרך המשי.\n" +
2001 "\n" +
2002 …ם מלחמות בתוך המדינה ומחלקים את המדינה למספר מדינות קטנות. תקופה זו ידועה כתקופת שלוש הממלכות.\n" +
2003 "\n" +
2004 "[עריכה] ג'ין, שש עשרה הממלכות והשושלות הדרומית והצפונית: התקופה האפלה של סין\n" +
2005 "\n" +
2006 " ערך מורחב – שושלת ג'ין\n" +
2007 "\n" +
2008 …יסר טאיוון, שהקים את השושלות הצפוניות, סדרה של משטרים מקומיים ששלטו בסין שמצפון לנהר היאנג צה.\n" +
2009 "\n" +
2010 …ת הצפונית והדרומית. שושלת סוי קצרת המועד, הצליחה לאחד את המדינה ב589 לאחר כמעט 300 שנות פירוד.\n" +
2011 "\n" +
2012 "[עריכה] שושלת טאנג: חזרה לשיגשוג\n" +
2013 "\n" +
2014 " ערך מורחב – שושלת טאנג\n" +
2015 "\n" +
2016 …ת בשנית בידי שליטים מקומיים. תקופה נוספת של כאוס הגיעה למדינה: תקופת חמש השושלות ועשר הממלכות.\n" +
2017 "\n" +
2018 "[עריכה] שושלת סונג ושכנותיה הצפוניות, ליאו וג'ין\n" +
2019 "\n" +
2020 " ערך מורחב – שושלת סונג\n" +
2021 "\n" +
2022 …וחים משמעותיים בטכנולוגיה, ככל הנראה עקב הלחץ הצבאי שהופעל על ממלכת סונג מצד שכנותיה הצפוניות.\n" +
2023 "\n" +
2024 "[עריכה] המונגולים\n" +
2025 "\n" +
2026 …סין ושבירתה הייתה בייג'ינג (בייג'ינג הייתה בירתה של שושלת גי'ן אך השושלת לא שלטה על סין כולה).\n" +
2027 "\n" +
2028 "[עריכה] תחייתה מחדש של התרבות הסינית\n" +
2029 "\n" +
2030 …נה וספרים רבים נדפסו. יש הטוענים כי שהאומה הסינית בתקופת מינג הייתה האומה המתקדמת ביותר בעולם.\n" +
2031 "\n" +
2032 …ושלת סונג, אך כעת הם חלו גם על סוחרים זרים מה שהביא במהרה לגוויעת סחר החוץ בין סין לשאר העולם.\n" +
2033 "\n" +
2034 …ותר על אף שהחצר הקיסרית עשתה שימוש נרחב בפקידים ממשלתיים שהיו אחראיים לתפקודה השוטף של המדינה.\n" +
2035 "\n" +
2036 … מרכז אורבני מצומצם ובמקום זאת צמחו מספר רב של ערים שהיוו מרכזים מקומיים לאזורים המקיפים אותן.\n" +
2037 "\n" +
2038 "[עריכה] תקופת מינג: מהתפתחות לבידוד\n" +
2039 "\n" +
2040 " ערך מורחב – שושלת מינג\n" +
2041 "\n" +
2042 …אם והצי הימי שלה הפליג במסעותיו עד לחופי אפריקה. הסינים גם הצליחו לייצר השפעה מסוימת בטורקסטן.\n" +
2043 "\n" +
2044 …שון של הה, כלל 62 ספינות שנשאו 28,000 מלחים – ללא ספק המסע הימי הגדול ביותר בהיסטוריה האנושית.\n" +
2045 "\n" +
2046 …ד זה ננקט כדי להגן על הקיסרות מפני התקפות של שודדי ים. הגבלות אלו בוטלו לבסוף באמצע המאה ה-17.\n" +
2047 "\n" +
2048 "[עריכה] שושלת צ'ינג\n" +
2049 "\n" +
2050 " ערך מורחב – שושלת צ'ינג\n" +
2051 "\n" +
2052 …ילת תקופת שלטונם יש לזקוף לזכות כוחם הצבאי האדיר והמיומן ששולב עם מיומנויות בירוקרטיות סיניות.\n" +
2053 "\n" +
2054 …תקופת צ'ינג ואוכלוסיית המדינה, שבשנת 1700 מנתה 100 מיליון נפש, הגיעה לכדי 220 מליון בשנת 1800.\n" +
2055 "\n" +
2056 "\n" +
2057 "בקריקטורה צרפתית מפורסמת זו, נראית חלוקתה של סין בין בריטניה, גרמניה, רוסיה, צרפת ויפן\n" +
2058 "בקריקטורה צרפתית מפורסמת זו, נראית חלוקתה של סין בין בריטניה, גרמניה, רוסיה, צרפת ויפן\n" +
2059 "\n" +
2060 …מוסלמיות ששאפו לעצמאות וחוזקו על ידי רוסיה ייבשו את קופת המדינה וכמעט שהביאו לנפילת השלטון בה.\n" +
2061 "\n" +
2062 …או בעיקר על ידי כוחות המערב שבאותו הזמן עשו במדינה כבשלהם וניצלו את שווקיה ואת מערכתה הכלכלית.\n" +
2063 "\n" +
2064 …דש\" נחלו תבוסות משפילות הן במלחמת סין-צרפת (1885-1883) והן במלחמת סין-יפן הראשונה (1895-1894)\n" +
2065 "\n" +
2066 …ה של הקיסרית (יש הטוענים שהוא הורעל על ידה) הרס את הסיכוי האחרון לביסוס הנהגה אפקטיבית במדינה.\n" +
2067 "\n" +
2068 "[עריכה] הרפובליקה הסינית\n" +
2069 "\n" +
2070 " ערך מורחב – היסטוריה של הרפובליקה הסינית\n" +
2071 "\n" +
2072 …של יואן נחלקה בין הממשל הרפובליקני החדש, ובין מצביאים מקומיים ששלטו באזוריהם עוד מתקופת צ'ינג.\n" +
2073 "\n" +
2074 … את הזרעים לקונפליקט בלתי ניתן לגישור בין הימין והשמאל בסין, קונפליקט שהמשיך עד לסופה של המאה.\n" +
2075 "\n" +
2076 … ביותר במדינה אל עבר צפון מערבה של המדינה לפרובינציית שאאנסי שם הקימו לעצמם בסיסי לוחמת גרילה.\n" +
2077 "\n" +
2078 …שתי המפלגות המשיכה לאחר תבוסתם של היפנים ב-1945, וב-1949 שלטו הקומוניסטים ברוב שטחה של המדינה.\n" +
2079 "\n" +
2080 "[עריכה] הרפובליקה העממית של סין\n" +
2081 "\n" +
2082 " ערך מורחב – היסטוריה של הרפובליקה העממית של סין\n" +
2083 "\n" +
2084 "פרק זה לוקה בחסר. אתם מוזמנים לתרום לוויקיפדיה ולהשלים אותו. ראו פירוט בדף השיחה.\n" +
2085 "\n" +
2086 …ינו (סוף 2004) בטיוואן אך היא טרם הכריזה עצמאות והיא אינה מוכרת רשמית כמדינה על ידי שאר העולם.\n" +
2087 "\n" +
2088 …כאשר שינויים פוליטים ברפובליקה הסינית הביאו אותה להפסקת הטענה הפומבית להיותה ממשלת סין היחידה.\n" +
2089 "\n" +
2090 "[עריכה] ראו גם\n" +
2091 "\n" +
2092 " * לוח זמנים של ההיסטוריה של סין – טבלה המתארת את האירועים והאישים החשובים בתולדותיה של סין.\n"…
2093 "\n" +
2094 "[עריכה] לקריאה נוספת\n" +
2095 "\n" +
2096 " * עמנואל צ' י' שו, צמיחתה של סין המודרנית, הוצאת שוקן, 2005.\n" +
2097 "\n" +
2098 "[עריכה] קישורים חיצוניים\n" +
2099 "\n" +
2100 " * ירדן ניר-בוכבינדר, סין אימנו, קונפוציוס אבינו, באתר \"האייל הקורא\"\n" +
2101 "\n" +
2102 "\n" +
2103 "[עריכה] הערות שוליים\n" +
2104 "\n" +
2105 " 1. ^ סין של תקופת הברונזה בגלריה הלאומית לאמנות של ארצות-הברית\n" +
2106 " 2. ^ כתב על חרסים מאתר ארליטואו (כתוב בסינית מפושטת)\n";
2110 "中国の歴史\n" +
2111 "出典: フリー百科事典『ウィキペディア(Wikipedia)』\n" +
2112 "移動: ナビゲーション, 検索\n" +
2113 "中国歴史\n" +
2114 "中国の歴史\n" +
2115 "元謀・藍田・北京原人\n" +
2116 "神話伝説(三皇五帝)\n" +
2117 "黄河・長江文明\n" +
2118 "夏\n" +
2119 "殷\n" +
2120 "周 西周\n" +
2121 "東周 春秋\n" +
2122 "戦国\n" +
2123 "秦\n" +
2124 "漢 前漢\n" +
2125 "新\n" +
2126 "後漢\n" +
2127 "三国 魏 呉 蜀\n" +
2128 "晋 西晋\n" +
2129 "東晋 十六国\n" +
2130 "南北朝 宋 北魏\n" +
2131 "斉\n" +
2132 "梁 西魏 東魏\n" +
2133 "陳 北周 北斉\n" +
2134 "隋\n" +
2135 "唐\n" +
2136 "五代十国\n" +
2137 "宋 北宋 遼 西夏\n" +
2138 "南宋 金\n" +
2139 "元\n" +
2140 "明 北元\n" +
2141 "後金 南明 大順\n" +
2142 "清\n" +
2143 "中華民国\n" +
2144 "中華人民共和国 (参考:\n" +
2145 "台湾問題)\n" +
2146 "\n" +
2147 "中国の歴史(ちゅうごくのれきし)、或いは中国史(ちゅうごくし)\n" +
2148 "\n" +
2149 "中国の黄河文明は古代の四大文明の一つに数えられ、また黄河文明よりも更に遡る長江文明が存在した。\n" +
2150 "目次\n" +
2151 "[非表示]\n" +
2152 "\n" +
2153 " * 1 王朝、政権の変遷\n" +
2154 " * 2 概略\n" +
2155 " o 2.1 先史人類史\n" +
2156 " o 2.2 文明の萌芽\n" +
2157 " + 2.2.1 黄河文明\n" +
2158 " + 2.2.2 長江文明\n" +
2159 " + 2.2.3 その他\n" +
2160 " o 2.3 先秦時代\n" +
2161 " + 2.3.1 三代\n" +
2162 " + 2.3.2 春秋戦国\n" +
2163 " o 2.4 秦漢帝国\n" +
2164 " o 2.5 魏晋南北朝時代\n" +
2165 " o 2.6 隋唐帝国\n" +
2166 " o 2.7 五代十国・宋\n" +
2167 " o 2.8 モンゴル帝国\n" +
2168 " o 2.9 明清帝国\n" +
2169 " o 2.10 中国の半植民地化\n" +
2170 " o 2.11 中華民国\n" +
2171 " + 2.11.1 革命後の中国の政局\n" +
2172 " + 2.11.2 袁世凱の台頭と帝制運動(1913年~1916年)\n" +
2173 " + 2.11.3 袁世凱死後の政局(1916年~1920年)\n" +
2174 " + 2.11.4 国民革命(1920年~1928年)\n" +
2175 " + 2.11.5 国民政府(1928年~1931年)\n" +
2176 " + 2.11.6 抗日戦争(1931年~1937年)\n" +
2177 " + 2.11.7 日中戦争(1937年~1945年)\n" +
2178 " + 2.11.8 漢民族以外の民族の動向\n" +
2179 " # 2.11.8.1 モンゴルとチベットでの動き\n" +
2180 " # 2.11.8.2 東トルキスタン(新疆)での動き\n" +
2181 " o 2.12 中華人民共和国\n" +
2182 " + 2.12.1 社会主義国化と粛清(1949年~1957年)\n" +
2183 " + 2.12.2 中国共産党の対ソ自立化(1958年~1965年)\n" +
2184 " + 2.12.3 文化大革命前期(1966年~1969年)\n" +
2185 " + 2.12.4 文化大革命後期(1969~1976年)\n" +
2186 " + 2.12.5 改革開放以後の現在(1976年~)\n" +
2187 " # 2.12.5.1 一党独裁\n" +
2188 " # 2.12.5.2 少数民族問題\n" +
2189 " * 3 人口の変遷\n" +
2190 " * 4 地方行政制度\n" +
2191 " o 4.1 封建制度(前1600年頃~前221年)\n" +
2192 " o 4.2 郡県制度(前221年~249年)\n" +
2193 " o 4.3 軍府による広域行政(249年~583年)\n" +
2194 " o 4.4 州県制(583年~1276年)\n" +
2195 " * 5 祭祀制度\n" +
2196 " * 6 外交\n" +
2197 " o 6.1 漢帝国\n" +
2198 " o 6.2 魏晋南北朝時代\n" +
2199 " o 6.3 隋唐帝国\n" +
2200 " * 7 関連項目\n" +
2201 " * 8 脚注\n" +
2202 "\n" +
2203 "[編集] 王朝、政権の変遷\n" +
2204 "現在の中国、すなわち中華人民共和国の領域\n" +
2205 "現在の中国、すなわち中華人民共和国の領域\n" +
2206 "\n" +
2207 " * 長江文明\n" +
2208 " * 黄河文明\n" +
2209 " * 夏(紀元前2070年頃 - 紀元前1600年頃\n" +
2210 " * 殷(紀元前1600年頃 - 紀元前12世紀・紀元前11世紀ごろ)\n" +
2211 "\n" +
2212 " * 周(紀元前12世紀・紀元前11世紀ごろ - 紀元前256年)…殷を倒し、西周建国。克殷の年代については諸説あり、はっきりしない。\n" +
2213 …o 春秋時代(紀元前770年 - 紀元前403年)…紀元前453年晋が韓魏趙に分割された時点、または紀元前403年韓魏趙が諸侯に列した時点をもって春秋時代の終わり、戦国時代の始まりとする。\n" +
2214 " o 戦国時代(紀元前403年 - 紀元前221年)…晋が韓・趙・魏に分裂し、戦国時代突入。\n" +
2215 " * 秦(紀元前221年 - 紀元前207年)…秦王・政が6国を滅ぼし中華統一。\n" +
2216 " * 漢\n" +
2217 " o 前漢(紀元前206年 - 8年)…秦滅亡後、楚の項羽との楚漢戦争に勝ち、劉邦が建国。\n" +
2218 " o 新(8年 - 23年)…外戚の王莽が前漢皇帝から帝位を簒奪し建国。\n" +
2219 " o 後漢(25年 - 220年)…前漢の景帝の子孫の劉秀(光武帝)が王莽軍を破り、漢を再興。\n" +
2220 " * 三国時代(220年 - 280年)\n" +
2221 " o 魏、蜀(蜀漢・漢)、呉…曹操の子曹丕が献帝から禅譲を受け即位すると、蜀の劉備も漢皇帝を名乗り即位、さらに呉の孫権も大帝として即位し、三国時代に入る。\n" +
2222 " * 晋(265年 - 420年)\n" +
2223 " o 西晋(265年 - 316年)…晋王司馬炎が魏の元帝より禅譲を受け即位し建国。だが、異民族五胡の侵入により衰退。異民族の漢に滅ぼされた。\n" +
2224 " o 東晋(317年 - 420年)…皇族でただ一人生き残った琅邪王・司馬睿は江南に逃れ、建康で即位(元帝)。これを中原の晋と区別して東晋という。\n" +
2225 " o 五胡十六国時代(304年 - 439年)\n" +
2226 " * 南北朝時代(439年 - 589年)\n" +
2227 " o 北魏、東魏、西魏、北斉、北周\n" +
2228 " o 宋、斉、梁、陳\n" +
2229 " * 隋(581年 - 619年)\n" +
2230 " * 唐(618年 - 907年)\n" +
2231 " o 武周\n" +
2232 " * 五代十国時代\n" +
2233 " o 後梁、後唐、後晋、後漢、後周……五代(中原を中心とする国)\n" +
2234 " o 呉、南唐・閩・呉越・荊南・楚・南漢・前蜀・後蜀・北漢……十国(中華東西南北に拠る勢力)\n" +
2235 " * 宋\n" +
2236 " o 北宋(960年 - 1127年)\n" +
2237 " o 南宋(1127年 - 1279年)\n" +
2238 " o 遼、西夏、金\n" +
2239 " * 元(1271年 - 1368年)\n" +
2240 " * 明(1368年 - 1644年)\n" +
2241 " o 南明\n" +
2242 " * 清(1616年 - 1912年)(1616年 - 1636年は後金、それ以前はマンジュ国)\n" +
2243 " o 太平天国、満州国\n" +
2244 " * 中華民国(台湾)(1912年 - 現在)\n" +
2245 " * 中華人民共和国(1949年 - 現在)\n" +
2246 "\n" +
2247 "[編集] 概略\n" +
2248 "\n" +
2249 "[編集] 先史人類史\n" +
2250 "\n" +
2251 "中国に現れた最初期の人類としては、元謀原人や藍田原人、そして北京原人が知られている。\n" +
2252 "\n" +
2253 "[編集] 文明の萌芽\n" +
2254 "\n" +
2255 …長江文明は稲作が中心であった。黄河文明が、歴史時代の殷(商)や周などにつながっていき、中国大陸の歴史の中軸となった。長江文明は次第に、中央集権国家を創出した黄河文明に同化吸収されていった。\n" +
2256 "\n" +
2257 "[編集] 黄河文明\n" +
2258 "龍山文化時代の高杯。1976年山東省出土\n" +
2259 "龍山文化時代の高杯。1976年山東省出土\n" +
2260 "\n" +
2261 "黄河文明は、その後の中国の歴史の主軸となる。\n" +
2262 "\n" +
2263 " * 裴李崗文化…紀元前7000?~紀元前5000?。一般的な「新石器時代」のはじまり。定住し、農業も行われていた。河南省(黄河中流)。土器は赤褐色\n" +
2264 " * 老官台文化…紀元前6000?~紀元前5000?。土器作りや粟作りが行われていた。陝西省(黄河上流)。土器は赤色。\n" +
2265 " * 北辛文化…紀元前6000?~紀元前5000?。土器は黄褐色。山東省(黄河下流)\n" +
2266 " * 磁山文化…紀元前6000?~紀元前5000?。土器は赤褐色。河北省(黄河下流)\n" +
2267 …て存在。このころは母系社会で、農村の階層化も始まった。文化後期になると、社会の階層化、分業化が進み、マルクス経済学でいうところの原始共産制は仰韶文化のころに終焉したと見られる。土器は赤色。\n" +
2268 " * 後岡文化…紀元前5000?~紀元前4000?。北辛文化が発展。河南省。\n" +
2269 " * 大汶口文化…紀元前4300?~紀元前2400?。土器は前期は赤色(彩陶)、後期は黒色(黒陶)。なお、この区分は黄河文明全体に見られる。山東省。\n" +
2270 " * 龍山文化…紀元前2500?~紀元前2000?。大汶口文化から発展。後期黄河文明最大の文化。土器は黒色。山東省。\n" +
2271 " * 二里頭文化…紀元前2000?~紀元前1600?。遺跡の中心部には二つの宮殿がある。河南省。\n" +
2272 "\n" +
2273 "[編集] 長江文明\n" +
2274 "母なる長江\n" +
2275 "母なる長江\n" +
2276 "\n" +
2277 "長江文明は黄河文明が萌芽する遥か前より栄えていた。夏王朝の始祖とされる禹が南方出身であるとされるため、この長江流域に夏王朝が存在したのではないかという説[1]がある。\n" +
2278 "\n" +
2279 " * 玉蟾岩遺跡…湖南省(長江中流)。紀元前14000年?~紀元前12000年?の稲モミが見つかっているが、栽培したものかは確定できない。\n" +
2280 …桶環遺跡…江西省(長江中流)。紀元前12000年ごろ?の栽培した稲が見つかっており、それまで他から伝播してきたと考えられていた中国の農耕が中国独自でかつ最も古いものの一つだと確かめられた。\n" +
2281 " * 彭頭山文化…湖南省(長江中流)。紀元前7000年?~紀元前5000年?。散播農法が行われており、中国における最古の水稲とされる。\n" +
2282 …~紀元前3300年?。彩文紅陶(紋様を付けた紅い土器)が特徴で、後期には黒陶・灰陶が登場。灌漑農法が確立され、住居地が水の補給のための水辺から大規模に農耕を行う事の出来る平野部へ移動した。\n" +
2283 " * 屈家嶺文化…湖北省。紀元前3000年?~紀元前2500年?大渓文化を引き継いで、ろくろを使用した黒陶が特徴。河南地方の黄河文明にも影響を与えたと考えられる。\n" +
2284 …門県石家河に大規模な都城を作った紀元前2500年頃を境として屈家嶺と区別する。この都城は南北1.3Km、東西1.1Kmという大きさで、上述の黄河流域の部族と抗争したのはこの頃と考えられる。\n" +
2285 " * 河姆渡文化 …紀元前5000年?~紀元前4000年?下流域では最古の稲作。狩猟や漁労も合わせて行われ、ブタの家畜化なども行われた。\n" +
2286 …ている。分業や階層化も行われたと見られ、殉死者を伴う墓が発見されている。黄河文明の山東竜山文化とは相互に関係があったと見られ、同時期に衰退したことは何らかの共通の原因があると見られている。\n" +
2287 …の地域、おそらくは黄河流域からの技術の流入と考えられる。長江文明と同じく文字は発見されていないが、「巴蜀文字」と呼ばれる文字らしきものがあり、一部にこれをインダス文字と結びつける説もある。\n" +
2288 "\n" +
2289 "[編集] その他\n" +
2290 "\n" +
2291 " * 新楽遺跡…遼寧省(遼河流域)。紀元前5200年?ごろの定住集落。母系社会が定着し、農業も行われていた。\n" +
2292 "\n" +
2293 "[編集] 先秦時代\n" +
2294 "\n" +
2295 "[編集] 三代\n" +
2296 "\n" +
2297 "史記では伝説と目される三皇五帝時代に続いて夏[2]王朝について記述されている。夏については実在が確かでなくまた定説もない。\n" +
2298 "\n" +
2299 …を行っていた(神権政治)。殷は以前は山東で興ったとされたが、近年は河北付近に興ったとする見方が有力で、黄河文明で生まれた村のうち強大になり発展した都市国家の盟主であった[4]と考えられる。\n" +
2300 "\n" +
2301 …陽にあり、西周の故地には秦が入る。これ以降を春秋時代と呼ぶ。春秋時代には、周王朝の権威はまだ残っていたが、紀元前403年から始まるとされる戦国時代には、周王朝の権威は無視されるようになる。\n" +
2302 "\n" +
2303 "[編集] 春秋戦国\n" +
2304 "諸子百家の一、孔子\n" +
2305 "諸子百家の一、孔子\n" +
2306 "\n" +
2307 "春秋戦国時代は、諸侯が争う戦乱の時代であった。\n" +
2308 "\n" +
2309 …貨幣も使用し始めやがて領土国家に変貌しその国都となった旧都市国家は30万人規模の都市に変貌する。また鉄器が普及したこともあいまって、農業生産も増大した。晋の分裂以後を一般に戦国時代という。\n" +
2310 "\n" +
2311 …のような戦乱の世をどのように過ごすべきかという思想がさまざまな人たちによって作られた。このような思想を説いた人たちを諸子百家(陰陽家、儒家、墨家、法家、名家、道家、兵家等が代表的)という。\n" +
2312 "\n" +
2313 "[編集] 秦漢帝国\n" +
2314 "始皇帝\n" +
2315 "\n" +
2316 …にあった。秦王政は、他の6つの列強を次々と滅ぼし、紀元前221年には史上はじめての中国統一を成し遂げた。秦王政は、自らの偉業をたたえ、王を超える称号として皇帝を用い、自ら始皇帝と名乗った。\n" +
2317 "兵馬俑\n" +
2318 "\n" +
2319 …事作戦は人々に多大な負担を与えた。そのため、紀元前210年に始皇帝が死ぬと、翌年には陳勝・呉広の乱という農民反乱がおきた。これに刺激され各地で反乱がおき、ついに秦は紀元前206年に滅びた。\n" +
2320 "漢の偉大な発明、紙\n" +
2321 "漢の偉大な発明、紙\n" +
2322 "\n" +
2323 …じられており、農民の救済策が検討され、富商を中心に増税をおこなうなど大土地所有を抑制しようと努力した。また儒教の国教化に関連して儒教の教義論争がしばしば宮廷の重大問題とされるようになった。\n" +
2324 "\n" +
2325 …た。初期の後漢王朝は豪族連合的な政権であったが、章帝の時代までは中央集権化につとめ安定した政治が行われた。しかし安帝時代以後外戚や宦官の権力の増大と官僚の党派対立に悩まされるようになった。\n" +
2326 "\n" +
2327 "[編集] 魏晋南北朝時代\n" +
2328 "三国決戦の地、赤壁\n" +
2329 "三国決戦の地、赤壁\n" +
2330 "\n" +
2331 …一するまで、一時期を除いて中国は分裂を続けた。この隋の再統一までの分裂の時代を魏晋南北朝時代という。また、この時期には日本や朝鮮など中国周辺の諸民族が独自の国家を形成し始めた時期でもある。\n" +
2332 "\n" +
2333 …して、221年には、現在の四川省に割拠していた劉備が皇帝となり、蜀を建国した。さらに、江南の孫権も229年に皇帝と称して、呉を建国した。この魏・呉・蜀の三国が並立した時代を三国時代という。\n" +
2334 "\n" +
2335 …たのは魏であった。魏は後漢の半分以上の領土を継承したが、戦乱で荒廃した地域に積極的な屯田をおこない、支配地域の国力の回復につとめた。魏では官吏登用法として、九品官人法[5]がおこなわれた。\n" +
2336 "\n" +
2337 …難した晋王朝(南に移ったあとの晋を東晋という)が支配した。この時期は、戦乱を憎み、宗教に頼る向きがあった。代表的な宗教が仏教と道教であり、この2つの宗教は時には激しく対立することがあった。\n" +
2338 "\n" +
2339 …より散文、書画等の六朝文化と呼ばれる文化が発展した。東晋滅亡後、宋・斉・梁・陳という4つの王朝が江南地方を支配したが、貴族が強い力を握ることは変わらなかった。梁の武帝は仏教の保護に努めた。\n" +
2340 "\n" +
2341 …西魏と東魏に分裂した。西魏は北周へと、東魏は北斉へと王朝が交代した。577年には北周が北斉を滅ぼしたが、581年に隋が北周にとって代わった。589年に隋は南方の陳を滅ぼし、中国を統一した。\n" +
2342 "\n" +
2343 "魏晋南北朝表も参照。\n" +
2344 "\n" +
2345 "[編集] 隋唐帝国\n" +
2346 "現在でも使用される世界最大の大運河\n" +
2347 "現在でも使用される世界最大の大運河\n" +
2348 "\n" +
2349 …を測る科挙を採用した。しかし、文帝の後を継いだ煬帝は、江南・華北を結ぶ大運河を建設したり、度重なる遠征を行ったために、民衆の負担が増大した。このため農民反乱が起き、618年に隋は滅亡した。\n" +
2350 "\n" +
2351 …長安は、西方にはシルクロードによってイスラム帝国や東ローマ帝国などと結ばれ、ゾロアスター教・景教・マニ教をはじめとする各地の宗教が流入した。また、文化史上も唐時代の詩は最高のものとされる。\n" +
2352 "当時世界最大の都市だった長安のシンボルタワー・大雁塔\n" +
2353 "当時世界最大の都市だった長安のシンボルタワー・大雁塔\n" +
2354 "\n" +
2355 "太宗の死後着々と力を付けた太宗とその子の高宗の皇后武則天はついに690年皇帝に即位した。前にも後にも中国にはこれのほかに女帝はいない。\n" +
2356 "\n" +
2357 …。875年から884年には黄巣の乱と呼ばれる農民反乱がおき、唐王朝の権威は失墜した。このような中、各地の節度使はますます権力を強めた。907年には、節度使の1人である朱全忠が唐を滅ぼした。\n" +
2358 "\n" +
2359 "[編集] 五代十国・宋\n" +
2360 "画像:Compass in a wooden frame.jpg\n" +
2361 "中国航海術の偉大な発明、羅針盤\n" +
2362 "\n" +
2363 …で節度使があい争った。この時代を五代十国時代という。この戦乱を静めたのが、960年に皇帝となって宋を建国した趙匡胤である。ただし、完全に中国を宋が統一したのは趙匡胤の死後の976年である。\n" +
2364 "\n" +
2365 …皇帝直属のものとし、中央集権・皇帝権力強化を進めた。科挙を受験した人々は大体が、地主層であった。これらの地主層を士大夫と呼び、のちの清時代まで、この層が皇帝権力を支え、官吏を輩出し続けた。\n" +
2366 "杭州\n" +
2367 "杭州\n" +
2368 "\n" +
2369 …い、中国文化を唯一絶対なものとせず、独自文化を保持し続けた。このような王朝を征服王朝という。後代の元や清も征服王朝であり、以降、中国文化はこれらの周辺諸民族の影響を強く受けるようになった。\n" +
2370 "\n" +
2371 …、この交易路は陶磁の道と呼ばれる。南宋の首都にして海上貿易の中心港だった杭州は経済都市として栄え、元時代に中国を訪れたマルコ・ポーロは杭州を「世界一繁栄し、世界一豊かな都市」と評している。\n" +
2372 "\n" +
2373 "文化的には、経済発展に伴って庶民文化が発達した。また、士大夫の中では新しい学問をもとめる動きが出て、儒教の一派として朱子学が生まれた。\n" +
2374 "\n" +
2375 "[編集] モンゴル帝国\n" +
2376 "\n" +
2377 …し、山東半島の南に流れていたため、漢民族は北方民族の攻勢を防げなかった。華北は満州系の女真族による金が、南部を南宋が支配していたが、金は1234年、南宋は1279年にモンゴルに滅ぼされた。\n" +
2378 "\n" +
2379 …の政権は中国に軸足を置くようになった。もっとも、西方が離反しても、帝国としての緩やかな連合は保たれ、ユーラシアには平和が訪れていた。1271年にクビライは元を国号として中国支配をすすめた。\n" +
2380 "宋代に発明された火薬は元寇の時使用され、日本の武士を驚かせた\n" +
2381 "宋代に発明された火薬は元寇の時使用され、日本の武士を驚かせた\n" +
2382 "\n" +
2383 …かった南宋への牽制のためにも日本に対して通交を求めたが、日本側は断った。このため二度に渡り日本に侵攻したが、成功しなかった(元寇)。元は三度目の日本侵攻を計画したが、実現には至らなかった。\n" +
2384 "\n" +
2385 "中国南部を支配していた南宋を1279年に元が滅ぼしたのはすでに見たとおりである。\n" +
2386 "\n" +
2387 …文学作品の執筆に携わった。この時代の曲は元曲と呼ばれ、中国文学史上最高のものとされる。また、モンゴル帝国がユーラシア大陸を広く支配したために、この時期は東西交易が前代に増して盛んになった。\n" +
2388 "\n" +
2389 …を陥落させ、元の政府はモンゴル高原へと撤退した。撤退後の元のことを北元といい、明と北元はしばしば争った。明側は1388年に北元は滅んだと称しているが、実質的にはその後も両者の争いは続いた。\n" +
2390 "\n" +
2391 "[編集] 明清帝国\n" +
2392 "鄭和の南海大遠征の時の巨艦・「宝船」\n" +
2393 "鄭和の南海大遠征の時の巨艦・「宝船」\n" +
2394 "\n" +
2395 …を南洋に派遣して、諸国に朝貢を求めた。この時の船が近年の研究によって長さ170m余、幅50m余という巨艦で、その約70年後の大航海時代の船の5倍から10倍近い船であったことが分かっている。\n" +
2396 "\n" +
2397 "また、永楽帝によって現在に至るまで世界最大の宮殿である紫禁城が北京に築かれた。\n" +
2398 "\n" +
2399 …岸には、倭寇と呼ばれる海上の無法者たちが襲撃を重ねていた。これは、海禁政策で貿易が自由にできなくなっていたためである。倭寇とモンゴルを併称して北虜南倭というが、北虜南倭は明を強く苦しめた。\n" +
2400 "紫禁城の中心、太和殿\n" +
2401 "紫禁城の中心、太和殿\n" +
2402 "\n" +
2403 "また、皇帝による贅沢や多額の軍事費用の負担は民衆に重税となって圧し掛かってきた。これに対し、各地で反乱がおき、その中で頭角をあらわした李自成が1644年に明を滅ぼした。\n" +
2404 "\n" +
2405 …た。17世紀後半から18世紀にかけて、康熙帝・雍正帝・乾隆帝という3人の賢い皇帝の下で、清の支配領域は中国本土と中国東北地方・モンゴルのほかに、台湾・東トルキスタン・チベットにまで及んだ。\n" +
2406 "\n" +
2407 "この清の支配領域が大幅に広がった時期は、『四庫全書』の編纂など文化事業も盛んになった。しかし、これは学者をこのような事業に動員して、異民族支配に反抗する暇をなくそうとした面もあった。\n" +
2408 "\n" +
2409 …、政府も一条鞭法と呼ばれる税を銀で払わせる税法を始めた。また、清代に入ると、人頭税を廃止し土地課税のみとする地丁銀制が始まった。また明清両代ともに商品経済が盛んになり、農業生産も向上した。\n" +
2410 "\n" +
2411 "[編集] 中国の半植民地化\n" +
2412 "フランス人が描いた中国半植民地化の風刺画。イギリス、ドイツ、ロシア、フランス、日本が中国を分割している。\n" +
2413 "フランス人が描いた中国半植民地化の風刺画。イギリス、ドイツ、ロシア、フランス、日本が中国を分割している。\n" +
2414 "\n" +
2415 …れ以降、イギリスをはじめとするヨーロッパの列強は中国に対し、不平等条約(治外法権の承認、関税自主権の喪失、片務的最恵国待遇の承認、開港、租借といった)を締結させ、中国の半植民地化が進んだ。\n" +
2416 "\n" +
2417 "国内的には、太平天国の乱などの反乱もしばしば起きた。これに対し、同治帝(在位1861年 - 1875年)の治世の下で、ヨーロッパの技術の取り入れ(洋務運動)が行われた。\n" +
2418 "\n" +
2419 …にも清は敗退した。これは洋務運動の失敗を意味するものであった。この戦争の結果、日本と清との間で結んだ下関条約により、李氏朝鮮の独立が認められ、中国の王朝が長年続けてきた冊封体制が崩壊した。\n" +
2420 "\n" +
2421 …月1日、革命派の首領の孫文によって南京で中華民国の樹立が宣言された。北京にいた清の皇帝溥儀(宣統帝)は、清朝政府内部の実力者である袁世凱により2月12日に退位させられ、清は完全に滅亡した。\n" +
2422 "\n" +
2423 "[編集] 中華民国\n" +
2424 "\n" +
2425 "[編集] 革命後の中国の政局\n" +
2426 "\n" +
2427 …打倒した時点で革命に参加した勢力どうしで利害をめぐって対立するようになり、政局は混乱した。各地の軍閥も民国政府の税金を横領したり勝手に新税を導入して独自の財源を持つようになり、自立化した。\n" +
2428 "\n" +
2429 "[編集] 袁世凱の台頭と帝制運動(1913年~1916年)\n" +
2430 "袁世凱\n" +
2431 "袁世凱\n" +
2432 "\n" +
2433 …月袁は正式な大総統となり、さらに11月には国民党を非合法化し、解散を命じた。1914年1月には国会を廃止、5月1日には立法府の権限を弱め大総統の権力を大幅に強化した中華民国約法を公布した。\n" +
2434 "\n" +
2435 …に列強による中国の半植民地化をますます進めることにもなった。第一次世界大戦が始まると、新規借款の望みがなくなったため、袁は財政的に行き詰まった。また日本が中国での権益拡大に積極的に動いた。\n" +
2436 "\n" +
2437 …帝制度へ移行し、自身が皇帝となることを望んだ。日本も立憲君主制には当初賛成していたようだが、中国国内で帝制反対運動が激化すると反対に転じ外交圧力をかけた。1916年袁は失意のうちに没した。\n" +
2438 "\n" +
2439 "[編集] 袁世凱死後の政局(1916年~1920年)\n" +
2440 "\n" +
2441 …年5月4日、山東半島での主権回復と反日を訴えるデモ行進が始まった。これを五・四運動という。なお山東半島は1922年に返還された。1920年7月の安直戦争で直隷派に敗れたことで段は失脚した。\n" +
2442 "\n" +
2443 "[編集] 国民革命(1920年~1928年)\n" +
2444 "革命家・孫文\n" +
2445 "革命家・孫文\n" +
2446 "\n" +
2447 …ら武漢政府も反共に転じ、南京政府に吸収された。1928年6月南京政府の国民革命軍は北京の中華民国政府を打倒し、12月に張学良もこれを承認したことから、国民政府によって中国は再び統一された。\n" +
2448 "\n" +
2449 "[編集] 国民政府(1928年~1931年)\n" +
2450 "蒋介石\n" +
2451 "蒋介石\n" +
2452 "\n" +
2453 …年代前半には国民政府に叛旗を翻す形で地方政権が樹立される例が多くなり、軍事衝突なども起きた。1930年に閻錫山と汪兆銘が中心となった北平政府や1931年に孫科らがたてた広州政府などである。\n" +
2454 "\n" +
2455 "しかしこのような軍事的緊張は国民政府の中央軍を掌握していた蒋介石の立場を強めることにもなった。蒋介石は経済政策[8]でも手腕を発揮し影響力を増した。\n" +
2456 "\n" +
2457 "[編集] 抗日戦争(1931年~1937年)\n" +
2458 "満州国皇帝愛新覚羅溥儀\n" +
2459 "満州国皇帝愛新覚羅溥儀\n" +
2460 "\n" +
2461 …反発した。1931年9月、満州事変がおこり、関東軍によって日本政府の意向を無視して大規模な武力行動がおこなわれた。しかし列強はこれを傍観する姿勢をとったので、日本政府はこの行動を追認した。\n" +
2462 "\n" +
2463 …の共同管理による自治政府とするべきという妥協案を示したが、日本は採択に反対した。1933年5月日中間で停戦協定(塘沽協定)が結ばれた。1934年には満州国は帝制に移行し、満州帝国となった。\n" +
2464 "\n" +
2465 …略に立ち向かうことはできなかった。1934年には瑞金は国民党により陥落し、打撃を受けた中国共産党は長征と称して西部に移動し、組織の再編をはかった。長征の結果中国共産党は延安に拠点を移した。\n" +
2466 "\n" +
2467 "[編集] 日中戦争(1937年~1945年)\n" +
2468 "\n" +
2469 …国と全面戦争に入った(日中戦争)。これに対し、蒋介石は当初日本との戦いよりも中国共産党との戦いを優先していたが、西安事件により、二つの党が協力して日本と戦うことになった(第二次国共合作)。\n" +
2470 "カイロ会談に出席した蒋介石とアメリカのフランクリン・D・ルーズベルト大統領、イギリスのウィンストン・チャーチル首相\n" +
2471 "カイロ会談に出席した蒋介石とアメリカのフランクリン・D・ルーズベルト大統領、イギリスのウィンストン・チャーチル首相\n" +
2472 "\n" +
2473 …端を開いたが(太平洋戦争)、一方で中国で多くの戦力を釘付けにされるなど、苦しい状況に落ち込まされた。国民党政府は連合国側に所属し、アメリカやイギリスなどから豊富な援助を受けることとなった。\n" +
2474 "\n" +
2475 …府は連合国の1国として大きな地位を占めていたこともあり、戦勝国として有利な立場を有することとなり、日本だけでなくヨーロッパ諸国も租界を返還するなど、中国の半植民地化は一応の終わりを見せた。\n" +
2476 "\n" +
2477 …東が中華人民共和国の成立を宣言した。内戦に敗れた中国国民党率いる中華民国政府は台湾島に撤退し、現在に至るまで中国共産党率いる中華人民共和国と「中国を代表する正統な政府」の地位を争っている。\n" +
2478 "\n" +
2479 "[編集] 漢民族以外の民族の動向\n" +
2480 "\n" +
2481 "[編集] モンゴルとチベットでの動き\n" +
2482 "\n" +
2483 "辛亥革命により清国が消滅すると、その旧領をめぐって中国、モンゴル、チベットは、それぞれに自領域を主張した。\n" +
2484 "\n" +
2485 …して、モンゴルとチベットは、自分たちは清朝の皇帝に服属していたのであって中国という国家に帰属するものではなく、服属先の清帝退位後は中国と対等の国家であると主張し独立を目指す動きが強まった。\n" +
2486 "ポタラ宮、当時のチベットの中心地\n" +
2487 "ポタラ宮、当時のチベットの中心地\n" +
2488 "\n" +
2489 …入をゆるし、モンゴル・ロシア・中華民国はキャフタ協定に調印批准、チベット・イギリス・中華民国はシムラ協定(民国政府のみ調印、批准されなかった)が模索されたものの問題の解決には至らなかった。\n" +
2490 "\n" +
2491 …共産党の労農紅軍が、カム地方東部(四川省西部、当時西康省)に滞留中、同地のチベット人に「チベット人人民共和国」(博巴人民共和国)[9]を組織させたが、紅軍の退出とともに、ほどなく消滅した。\n" +
2492 "\n" +
2493 …分のみの独立を中華民国政府が承認することによって、チベットについては、1950年、十七ヶ条協定によってチベットの独立が否定され中華人民共和国の一地方となったことによって、一応の決着をみた。\n" +
2494 "\n" +
2495 "[編集] 東トルキスタン(新疆)での動き\n" +
2496 "\n" +
2497 …部下であった盛世才が実権を握るようになり、彼はソ連にならった政策を打ち出して徐々に権力を強化した。一方で1933年には南部で東トルキスタン共和国の独立が宣言されたが、わずか6ヶ月で倒れた。\n" +
2498 "\n" +
2499 "[編集] 中華人民共和国\n" +
2500 "\n" +
2501 "[編集] 社会主義国化と粛清(1949年~1957年)\n" +
2502 "「建国宣言」を行なう毛沢東\n" +
2503 "「建国宣言」を行なう毛沢東\n" +
2504 "\n" +
2505 …借していた大連、旅順が返還され、ソ連の経済援助の下で復興を目指すこととなった。1953年より社会主義化が進み、人民政治協商会議に代わって全国人民代表大会が成立、農業生産合作社が組織された。\n" +
2506 "\n" +
2507 …リカに対する緩衝国家あるいは衛星国家とみなすことも可能である。しかし徐々にデタント政策へと転回し始めていたソ連の対外政策は、中国共産党政府の中華民国に対する強硬政策と明らかに矛盾していた。\n" +
2508 "\n" +
2509 "[編集] 中国共産党の対ソ自立化(1958年~1965年)\n" +
2510 "\n" +
2511 …沢東はこのような報告を右派的な日和見主義であり、過渡的な問題に過ぎないと見ていたため、反対意見を封殺したが、あまりに急速な人民公社化は都市人口の異様な増大など深刻な問題を引き起こしていた。\n" +
2512 "\n" +
2513 …共産党政府はソ連の対外政策への不信からこれを断った。その後1959年6月ソ連は中ソ協定を一方的に破棄した。1960年には経済技術援助条約も打ち切られ、この年の中国のGNPは1%も下落した。\n" +
2514 "\n" +
2515 …な時期に入ったように思われた。劉少奇が第2次5ヶ年計画の失敗を人民公社による分権的傾向にあると指摘し、中央集権を目指した政治改革、個人経営を一部認めるなど官僚主義的な経済調整をおこなった。\n" +
2516 "\n" +
2517 …大革命の伏線となった。1964年中国は核実験に成功し、軍事的な自立化に大きな一歩を踏み出した。一方で1965年にアメリカによる北爆が始まりベトナム戦争が本格化すると、軍事的緊張も高まった。\n" +
2518 "\n" +
2519 "チベットでは独立運動が高まったが、政府はこれを運動家に対する拷問など暴力によって弾圧した。このため多数の難民がインドへ流入した。\n" +
2520 "\n" +
2521 "[編集] 文化大革命前期(1966年~1969年)\n" +
2522 "天安門広場は中華人民共和国時代にも多くの歴史の舞台となった\n" +
2523 "天安門広場は中華人民共和国時代にも多くの歴史の舞台となった\n" +
2524 "\n" +
2525 …青少年によって革命に賛同する組織である紅衛兵が結成された。毛沢東は「造反有理」(反動派に対する謀反には道理がある)という言葉でこの運動を支持したので、紅衛兵は各地で組織されるようになった。\n" +
2526 "\n" +
2527 …少奇を失脚させた。しかし文化大革命は政治だけにとどまることがなく、広く社会や文化一般にも批判の矛先が向けられ、反革命派とされた文化人をつるし上げたり、反動的とされた文物が破壊されたりした。\n" +
2528 "\n" +
2529 …に加担した。中央では周恩来らと文革小組の間で権力闘争がおこなわれた。1967年の後半になると、毛沢東は内乱状態になった国内を鎮めるために軍を紅衛兵運動の基盤であった学校や工場に駐屯させた。\n" +
2530 "\n" +
2531 …速に台頭した。1969年には中ソ国境の珍宝島で両国の軍事衝突があり(中ソ国境紛争)、軍事的緊張が高まったこともこれを推進した。同年採択された党規約で林彪は毛沢東の後継者であると定められた。\n" +
2532 "\n" +
2533 "[編集] 文化大革命後期(1969~1976年)\n" +
2534 "\n" +
2535 …が行われ、その犠牲者の合計数は数百万人とも数千万人とも言われている。また学生たちが下放され農村で働くなど、生産現場や教育現場は混乱し、特に産業育成や高等教育などで長いブランクをもたらした。\n" +
2536 "\n" +
2537 …連と敵対する日本やアメリカなどからの外交的承認を受け、この結果国連の常任理事国の議席も台湾島に遷都した中華民国政府(国民党政権)に変わって手にするなど、国際政治での存在感を高めつつあった。\n" +
2538 "\n" +
2539 "[編集] 改革開放以後の現在(1976年~)\n" +
2540 "返還された香港は中国経済の牽引都市になっている\n" +
2541 "返還された香港は中国経済の牽引都市になっている\n" +
2542 "\n" +
2543 …一党独裁を堅持しつつ、資本主義経済導入などの改革開放政策を取り、近代化を進めた(社会主義市場経済、鄧小平理論)。この結果、香港ほか日米欧などの外資の流入が開始され、中国経済は離陸を始めた。\n" +
2544 "\n" +
2545 "[編集] 一党独裁\n" +
2546 "\n" +
2547 "冷戦崩壊後に、複数政党による選挙や言論の自由などの民主主義化を達成した中華民国と違い、いまだに中国共産党政府による一党独裁から脱却できない中華人民共和国には多数の問題が山積している。\n" +
2548 "\n" +
2549 …の意見の違いがあるが、数百人から数万人に上るといわれている。しかし中国共産党政府はこの事件に関しては国内での正確な報道を許さず、事件後の国外からの非難についても虐殺の正当化に終始している。\n" +
2550 "\n" +
2551 …活動家に対する弾圧を加えるなどの前近代的な動きとの間で揺れている。この様な中、2003年には国内でSARSの大発生があったが、このときも政府は虚偽の発表を行なうなど問題の隠蔽を繰り返した。\n" +
2552 "\n" +
2553 …た経済的、法的インフラを引き継ぎ、中華人民共和国の経済の大きな推進役となっている。また、敵対している中華民国との間にも経済的な交流が進み、両国の首都の間に直行便が就航するまでになっている。\n" +
2554 "\n" +
2555 …いと諸外国から指摘されている。各省など地方も独自の産業振興策に走り、中国共産党中央政府に対して経済統計の水増し発表や災害などの情報隠蔽を行うなど、統計や発表の信憑性不足に拍車をかけている。\n" +
2556 "\n" +
2557 …る言論統制や貧富格差、地域格差など国内のひずみを放置し続ければ、いずれ内部崩壊を起こして再度混乱状態に陥り、ソ連同様に中華人民共和国という国家体制そのものが解体、消滅するという意見も多い。\n" +
2558 "\n" +
2559 "[編集] 少数民族問題\n" +
2560 "\n" +
2561 …よりウイグル語が廃れるなどの民族的なマイノリティ問題が発生している。またタクラマカン砂漠の石油資源利用や新疆南北の経済格差が広がっているなど、中国共産党政府の経済政策に対する批判も根強い。\n" +
2562 "\n" +
2563 …る権限拡大という現実主義的な主張もあらわれている。たとえば中国語教育を受けたウイグル人が中国共産党組織に参加する、新疆での中国共産党政府の経済政策に積極的に参加するといった事例も見られる。\n" +
2564 "\n" +
2565 …政府が不法な領土占拠をしていると訴えるとともに独立運動が継続されている。中国共産党政府はこれを武力で弾圧し続け、独立運動家への拷問などを行なったために、多数の難民が隣国のインドに流入した。\n" +
2566 "\n" +
2567 "[編集] 人口の変遷\n" +
2568 "\n" +
2569 "以下のデータは主に楊学通「計画生育是我国人口史発展的必然」(1980年)による。\n" +
2570 "時代 年代 戸数 人口 資料出所\n" +
2571 "(夏) 禹(前2205年とされる) 13,553,923 『帝王世紀』\n" +
2572 "秦 20,000,000? \n" +
2573 "前漢 平帝元始2年(2年) 12,233,062 59,594,978 『漢書』地理志\n" +
2574 "新 20,000,000? \n" +
2575 "後漢 順帝建康元年(144年) 9,946,919 49,730,550 『冊府元亀』\n" +
2576 "晋 武帝泰康元年(280年) 2,459,804 16,163,863 『晋書』食貨志\n" +
2577 "隋 煬帝大業2年(606年) 8,907,536 46,019,056 『隋書』地理志・食貨志\n" +
2578 "唐 玄宗天宝14年(755年) 8,914,709 52,919,309 『通志』\n" +
2579 "宋 神宗元豊3年(1080年) 14,852,684 33,303,889 『宋史』地理志\n" +
2580 "金 章宗明昌6年(1195年) 7,223,400 48,490,400 『金史』食貨志\n" +
2581 "元 世祖至元27年(1290年) 13,196,206 58,834,711 『元史』地理志\n" +
2582 "明 神宗万暦6年(1570年) 10,621,436 60,692,850 『続文献通考』\n" +
2583 "清 清初(1644年) 45,000,000 \n" +
2584 "聖祖康熙50年(1711年) 100,000,000以上 \n" +
2585 "高宗乾隆27年(1762年) 200,000,000以上 \n" +
2586 "高宗乾隆55年(1790年) 300,000,000以上 \n" +
2587 "仁宗嘉慶17年(1812年) 333,700,560 『東華録』\n" +
2588 "宣宗道光14年(1834年) 400,000,000以上 \n" +
2589 "中華民国 民国36年(1947年) 455,590,000 『統計提要』\n" +
2590 "中華人民共和国 1995年 1,211,210,000 『中国統計年鑑』\n" +
2591 "\n" +
2592 "[編集] 地方行政制度\n" +
2593 "\n" +
2594 "[編集] 封建制度(前1600年頃~前221年)\n" +
2595 "\n" +
2596 "殷・周の時代は封建制度[10]によって一定の直轄地以外は間接的に統治された。\n" +
2597 "\n" +
2598 "[編集] 郡県制度(前221年~249年)\n" +
2599 "\n" +
2600 …功臣や皇族のために設置された。しかし徐々に国の行政権限が回収されるとともに、推恩政策によって国の細分化が進められ、国は郡県と等しいものとなり、後漢時代には実質郡県制度そのままとなっていた。\n" +
2601 "\n" +
2602 …うに適用されたので、行政単位として郡以上に広域な州が現実的な行政単位として確立したと考えられている。が、軍政面と官吏登用面のほかにどれほど地方行政に貢献したか[13]はあまり明確ではない。\n" +
2603 "\n" +
2604 "[編集] 軍府による広域行政(249年~583年)\n" +
2605 "\n" +
2606 …般に細分化傾向にあり、南北朝前期には中国全土で5,60州、南北朝末期に至ると中国全土で300州以上になり、ひとつの州がわずか2郡、ひとつの郡はわずか2,3県しか含まないという有様であった。\n" +
2607 "\n" +
2608 "[編集] 州県制(583年~1276年)\n" +
2609 "\n" +
2610 …完成された。特定の州に折衝府が置かれ、自営農民を中心として府兵が組織され常備地方軍[15]とされた。唐では州の上に10の道も設置されたが、これは監察区域で行政単位ではないと考えられている。\n" +
2611 "\n" +
2612 "[編集] 祭祀制度\n" +
2613 "\n" +
2614 "中国でおこなわれた国家祭祀については皇帝祭祀を参照。\n" +
2615 "\n" +
2616 "[編集] 外交\n" +
2617 "\n" +
2618 "中国大陸の諸王朝は前近代まで基本的に東アジアでの優越的な地位を主張し、外交的には大国として近隣諸国を従属的に扱う冊封体制が主流であった。\n" +
2619 "\n" +
2620 "[編集] 漢帝国\n" +
2621 "\n" +
2622 …。また匈奴は基本的には冊封体制に組み込まれず、匈奴の単于と中国王朝の皇帝は原則的には対等であった。大秦(ローマ帝国のことを指すとされる)や大月氏などとの外交関係は冊封を前提とされていない。\n" +
2623 "\n" +
2624 "[編集] 魏晋南北朝時代\n" +
2625 "\n" +
2626 …しているように、あくまで名目的関係にとどめようという努力がなされており、南越と閩越の紛争においておこなわれたような中国王朝の主導による紛争解決などは期待されていないという見方が主流である。\n" +
2627 "\n" +
2628 "[編集] 隋唐帝国\n" +
2629 "\n" +
2630 …配しようとしたが、新羅に敗北し、願いは、叶わなかった。したがって隋・唐の冊封は実効支配とは無関係に形成されるようになった。唐の冊封体制の下では、律令的な政治体制・仏教的な文化が共有された。\n" +
2631 "\n" +
2632 "一方、突厥や西域諸国が服属すると、それらの地域に対する支配は直接支配としての州県、外交支配としての冊封とは異なった羈縻政策[17]がおこなわれた。\n" +
2633 "\n" +
2634 "[編集] 関連項目\n" +
2635 "\n" +
2636 " * 中華人民共和国\n" +
2637 " * 中華民国\n" +
2638 " * 中国帝王一覧\n" +
2639 " * 中国の首都\n" +
2640 " * 中国史時代区分表\n" +
2641 " o 夏商周年表\n" +
2642 " o 魏晋南北朝表\n" +
2643 " * 元号一覧\n" +
2644 " * 二十四史(清によって公認された正史)\n" +
2645 " * 中国史関係記事一覧\n" +
2646 " * マカオの歴史\n" +
2647 " * 香港の歴史\n" +
2648 " * 台湾の歴史\n" +
2649 " * 中国の通貨制度史\n" +
2650 " * 中国の仏教\n" +
2651 " * 中国法制史\n" +
2652 " * 中国化\n" +
2653 "\n" +
2654 "Wikibooks\n" +
2655 "ウィキブックスに中国史関連の教科書や解説書があります。\n" +
2656 "[編集] 脚注\n" +
2657 "\n" +
2658 …にある陵墓が禹のものであるとされ、戦国時代同地を支配していた越王勾践が禹の子孫を標榜していること、夏の桀王が『史記』鄭玄注などで淮河と長江の中間にある南巣で死んだとしていることなどによる。\n" +
2659 …掘結果から殷との連続性が確認されたが、細かい分析においては殷との非連続性も確認されているため、偃師二里頭遺跡が夏王朝のものであっても、夏が黄河流域起源の王朝であったかどうかは論争中である。\n" +
2660 " 3. ^ 代表的な遺跡殷墟が有名であるため日本では一般に殷と呼ばれるが、商の地が殷王朝の故郷とされており、商が自称であるという説もあるため、中国では商と呼ぶほうが一般的である。\n" +
2661 …ら侵入してきた遊牧民族による征服王朝だとする説もある。これは偃師二里頭遺跡では青銅器が現地生産されているのに対し、殷時代の青銅器は主に蜀方面で生産されていたことが確認されていることによる。\n" +
2662 …ものを望んでおらず、貴族社会の上位に皇帝権力を位置づけることでヒエラルキーを維持しようとしていたから、官職制度の根幹的な改変には至らず、官職の家柄による独占傾向を抑えることは出来なかった。\n" +
2663 " 6. ^ 1916年8月に復活された。\n" +
2664 " 7. ^ これはロシア革命に対するシベリア出兵において日中両軍が協力するという秘密条約である。\n" +
2665 …価格の中国の国内経済に対する影響が大幅に緩和された。このような経済政策を積極的に推進したのは国民政府財政部長の宋子文で、彼は孫文の妻宋慶齢の弟で、妹はのちに蒋介石と結婚した宋美齢であった。\n" +
2666 " 9. ^ 博巴あるいは波巴とはチベット人の自称。日本語に訳せばチベット人の人民政府という意味である。博巴と波巴はともに「ぽぱ」と読む。\n" +
2667 …かのぼる見方もあるが、広汎におこなわれたのは春秋あるいは戦国時代であったとする説もある。周の封建制を宗法制度の延長にあるものと捉え、封建儀礼を宗族への加盟儀礼の延長として捉える見方もある。\n" +
2668 …を9つの地方に分ける考え方が漠然と存在した。中国王朝の支配領域を「九州」といい、それがすなわち「天下」であった。ただし九州の概念は後漢時代にいたるまでははっきりしたものではなく一様でない。\n" +
2669 … 前漢成帝のときに州の監察権が御史中丞へ移行され、刺史が行政官となったという見方もあるが、後漢末期に刺史に軍事権が認められると、広域行政単位としての州はにわかに現実化したとみる見方もある。\n" +
2670 " 13. ^ このころの州を行政単位ではなく、軍管区のような概念上の管理単位であるとする見方も強い。\n" +
2671 " 14. ^ 北周の宇文護が創始した二十四軍制をもっていわゆる府兵制の成立と見做す見方があるがこれについては詳しいことはわからない。\n" +
2672 …募兵に基づく行軍制度もおこなわれており、大規模な対外戦争の際にはおもに折衝府非設置州を中心として兵が集められた。唐後期にはこの募兵制が常態化することで節度使制度がおこなわれるようになった。\n" +
2673 …内での銅鏡など出土品に記載された年号の問題などから、日本の古代王朝は特に南朝との外交関係を重視していたという見方が主流であるが、北朝との通交事実を明らかにしようという研究は続けられている。\n" +
2674 …り、漢字や律令などの文化の共有はおこなわれず、唐の支配が後退すると、唐の文化もこの地域では衰退することになった。冊封された国々で唐の支配が後退したあとも漢字文化が存続したことと対照的である。\n";
2678 "한국의 역사\n" +
2679 "위키백과 ― 우리 모두의 백과사전.\n" +
2680 " 이 문서는 남, 북으로 분단된 1945년 이전의 한국에 대한 역사를 주로 기술하고 있다.\n" +
2681 "\n" +
2682 "한국의 역사 (연표)\n" +
2683 "한국의 선사 시대 (유적)\n" +
2684 "환인 · 환웅 (신시)\n" +
2685 " 고조선 - 단군\n" +
2686 "진국\n" +
2687 "원\n" +
2688 "삼\n" +
2689 "국\n" +
2690 "|\n" +
2691 "삼\n" +
2692 "국\n" +
2693 "|\n" +
2694 "남\n" +
2695 "북\n" +
2696 "국\n" +
2697 "|\n" +
2698 "후\n" +
2699 "삼\n" +
2700 "국 삼한 옥\n" +
2701 "저 동\n" +
2702 "예 부\n" +
2703 "여\n" +
2704 "진\n" +
2705 "한 변\n" +
2706 "한 마\n" +
2707 "한\n" +
2708 " 가\n" +
2709 "야 \n" +
2710 " \n" +
2711 "백\n" +
2712 "제\n" +
2713 " \n" +
2714 " 고\n" +
2715 "구\n" +
2716 "려 \n" +
2717 "신\n" +
2718 "라 \n" +
2719 " \n" +
2720 "후\n" +
2721 "백\n" +
2722 "제 태\n" +
2723 "봉 발\n" +
2724 "해\n" +
2725 " \n" +
2726 "고려\n" +
2727 " \n" +
2728 " \n" +
2729 "조선\n" +
2730 " \n" +
2731 "대한제국\n" +
2732 "대한민국임시정부\n" +
2733 "일제 강점기 (조선총독부)\n" +
2734 "군정기\n" +
2735 "대한민국 조선민주주의\n" +
2736 "인민공화국\n" +
2737 "한국의 인물\n" +
2738 "한국의 역사는 구석기 시대 이후의 주로 한반도와 만주, 넓게는 동아시아 지역을 배경으로 발전되어 온 한국인의 역사이다.\n" +
2739 "목차 [숨기기]\n" +
2740 "1 선사 시대\n" +
2741 "1.1 유적에 의한 구분\n" +
2742 "1.2 문헌에 의한 구분\n" +
2743 "2 상고 시대 (B.C. 2333년 ~ A.D. 1세기)\n" +
2744 "2.1 고조선 시대\n" +
2745 "2.2 고조선 멸망 이후 여러나라의 성장\n" +
2746 "3 고대 시대 (A.D. 1세기~A.D. 900)\n" +
2747 "3.1 삼국시대\n" +
2748 "3.1.1 삼국시대 경제\n" +
2749 "3.1.2 삼국시대 정치\n" +
2750 "3.2 남북국시대\n" +
2751 "4 중세시대 (A.D. 918년 ~ A.D. 1392년)\n" +
2752 "4.1 고려의 정치\n" +
2753 "4.2 고려의 경제\n" +
2754 "4.3 고려의 사회\n" +
2755 "4.4 고려의 문화\n" +
2756 "5 근세시대 (A.D. 1392년 ~ A.D. 1506년)\n" +
2757 "5.1 초기 조선의 정치\n" +
2758 "5.2 초기 조선의 경제\n" +
2759 "5.3 초기 조선의 사회\n" +
2760 "5.4 초기 조선의 문화\n" +
2761 "6 근대 태동기 (A.D. 1506년 ~ A.D. 1907년)\n" +
2762 "6.1 후기 조선의 정치\n" +
2763 "6.2 후기 조선의 경제\n" +
2764 "6.3 후기 조선의 사회\n" +
2765 "6.4 후기 조선의 문화\n" +
2766 "7 근현대시대 (A.D. 1907년 ~ )\n" +
2767 "7.1 개괄\n" +
2768 "7.2 근대시대\n" +
2769 "7.3 현대시대\n" +
2770 "8 주석\n" +
2771 "9 같이 보기\n" +
2772 "10 참고문헌 및 링크\n" +
2773 "10.1 역사 일반\n" +
2774 "10.2 재단, 기타, 정부 기관\n" +
2775 "[편집]\n" +
2776 "선사 시대\n" +
2777 "\n" +
2778 "[편집]\n" +
2779 "유적에 의한 구분\n" +
2780 "한국의 구석기 시대(20만 년 이전 ~ 약 1만 년 전)\n" +
2781 "한국의 신석기 시대(약 1만 년 전 ~ 약 4천 년 전)\n" +
2782 "참고>> 웅기 부포리와 평양 만달리 유적, 통영 상노대도의 조개더미 최하층, 거창 임불리, 홍천 화화계리 유적 등을 중석기 유적지로 보는 사학자도 있다.\n" +
2783 "[편집]\n" +
2784 "문헌에 의한 구분\n" +
2785 "환국시대 [1](비공식)\n" +
2786 "신시[2] 또는 배달국 시대 [3](비공식)\n" +
2787 "[편집]\n" +
2788 "상고 시대 (B.C. 2333년 ~ A.D. 1세기)\n" +
2789 "\n" +
2790 …문화를 수용하면서 중국과 대립할 정도로 크게 발전하였으며, 만주와 한반도 각지에는 부여, 고구려, 옥저, 동예, 삼한 등 여러 나라가 성립될 수 있는 터전이 마련되었다.\n" +
2791 "[편집]\n" +
2792 "고조선 시대\n" +
2793 "단군조선\n" +
2794 "위만조선\n" +
2795 …제강점기를 전후로 점차 부인되어 현재에는 대한민국과 조선민주주의인민공화국의 역사학계 모두 이를 공식적으로 인정하지 않고 있으며, 사학자들도 대체적으로 이 설을 부정한다.\n" +
2796 "[편집]\n" +
2797 "고조선 멸망 이후 여러나라의 성장\n" +
2798 …풍습을 유지하였다. 많은 소국들이 경쟁하는 가운데 일부는 다른 나라를 병합되었고, 다시 연맹 왕국으로 발전하여 중앙 집권 국가를 형성할 수 있는 기반을 마련하게 되었다.\n" +
2799 "부여: 북부여, 동부여, 졸본부여\n" +
2800 "옥저\n" +
2801 "동예\n" +
2802 "삼한:\n" +
2803 "마한\n" +
2804 "변한\n" +
2805 "진한\n" +
2806 "[편집]\n" +
2807 "고대 시대 (A.D. 1세기~A.D. 900)\n" +
2808 "\n" +
2809 "[편집]\n" +
2810 "삼국시대\n" +
2811 "고구려\n" +
2812 "백제\n" +
2813 "신라\n" +
2814 "삼국시대 초반은 고구려와 백제가 주도했으나 진흥왕 이후 국력이 막강해진 신라가 삼국시대 후기를 주도 했다.\n" +
2815 "[편집]\n" +
2816 "삼국시대 경제\n" +
2817 "삼국의 경제는 기본적으로 물물교환 경제를 못 벗어난 체제였다고 한다.[출처 필요]\n" +
2818 "삼국사기에는 신라가 수도에 시전을 세웠다는 기록이 있다.\n" +
2819 "[편집]\n" +
2820 "삼국시대 정치\n" +
2821 "삼국의 정치는 기본적으로 중앙집권체제를 토대로 한 전제왕권 또는 귀족정치였다.\n" +
2822 "[편집]\n" +
2823 "남북국시대\n" +
2824 "신라\n" +
2825 "발해\n" +
2826 "[편집]\n" +
2827 "중세시대 (A.D. 918년 ~ A.D. 1392년)\n" +
2828 "\n" +
2829 "한국사에서는 고려시대를 중세시대로 보고 있다.\n" +
2830 "[편집]\n" +
2831 "고려의 정치\n" +
2832 …이었고, 통치 체제도 과거제를 실시하는 등 효율성과 합리성이 강화되는 방향으로 정비되었다. 특히, 사상적으로 유교 정치 이념을 수용하여 고대적 성격을 벗어날 수 있었다.\n" +
2833 …극복할 수 있었다. 12세기 후반에 무신들이 일으킨 무신정변은 종전의 문신 귀족 중심의 사회를 변화 시키는 계기가 되어 신분이 낮은 사람도 정치적으로 진출할 수 있었다.\n" +
2834 …기를 지나 고려 후기에 이르러서는 새롭게 성장한 신진 사대부를 중심으로 성리학이 수용되어 합리적이고 민본적인 정치 이념이 성립되었고, 이에 따른 사회 개혁이 진전되었다.\n" +
2835 "[편집]\n" +
2836 "고려의 경제\n" +
2837 … 양전 사업을 실시하고 호적을 작성하였다. 아울러 국가가 주도하여 산업을 재편하면서 경작지를 확대시키고, 상업과 수공업의 체제를 확립하여 안정된 경제 기반을 확보하였다.\n" +
2838 …으로 도시 상업이 발달하면서 점차 지방에서도 상업 활동이 증가하였다. 수공업도 관청 수공업 중심에서 점차 사원이나 농민을 중심으로한 민간 수공업을 중심으로 발전해 갔다.\n" +
2839 "[편집]\n" +
2840 "고려의 사회\n" +
2841 … 신분에는 그에 따른 역이 부과되었다. 그러나 그렇지 않은 경우도 있었는데, 향리로부터 문반직에 오르는 경우와 군인이 군공을 쌓아 무반으로 출세하는 경우를 들 수 있다.\n" +
2842 …군현으로 바뀌어 갔다. 흉년이나 재해 등으로 어려움을 겪는 백성들의 생활을 안정시키기 위하여 국가는 의창과 상평창을 설치하고, 여러 가지 사회 복지 시책을 실시 하였다.\n" +
2843 "[편집]\n" +
2844 "고려의 문화\n" +
2845 "고려 시대에 해당하는 중세 문화는 고대 문화의 기반 위에서 조상들의 노력과 슬기가 보태져 새로운 양상을 보였다.\n" +
2846 … 후기에는 성리학도 전래 되었다. 불교는 그 저변이 확대되어 생활 전반에 영향을 끼쳤다. 이런 가운데 불교 사상이 심화되고, 교종과 선종의 통합운동이 꾸준히 추진되었다.\n" +
2847 …조각에서는 고대의 성격을 벗어나 중세적 양식을 창출하였으며, 청자와 인쇄술은 세계적인 수준을 자랑하고 있다. 그림과 문학에서도 중세의 품격 높은 멋을 찾아 볼 수 있다.\n" +
2848 "[편집]\n" +
2849 "근세시대 (A.D. 1392년 ~ A.D. 1506년)\n" +
2850 "\n" +
2851 "한국사에서는 초기 조선 시대를 근세시대로 보고 있다.\n" +
2852 "[편집]\n" +
2853 "초기 조선의 정치\n" +
2854 …림이 16세기 후반 이후 정국을 주도해 나가면서 학파를 중심으로 사림이 분열하여 붕당을 이루었다. 이후 여러 붕당 사이에 서로 비판하며 견제하는 붕당 정치를 전개하였다.\n" +
2855 …서 정책의 협의나 집행 과정에서 유기적인 연결이 가능하도록 하였다. 조선은 고려에 비하여 한 단계 발전된 모습을 보여 주면서 중세 사회에서 벗어나 근세 사회로 나아갔다.\n" +
2856 "[편집]\n" +
2857 "초기 조선의 경제\n" +
2858 …결하고 재정 확충과 민생 안정을 위한 방안으로 농본주의 경제 정책을 내세웠다. 특히 애민사상을 주장하는 왕도 정치 사상에서 민생 안정은 가장 먼저 해결해야 할 과제였다.\n" +
2859 … 결이었던 경지 면적이 15세기 중엽에는 160여만 결로 증가하였다. 또한 농업 생산력을 향상시키기 위하여 새로운 농업 기술과 농기구를 개발하여 민간에 널리 보급하였다.\n" +
2860 …와 낭비가 조장되며 농업이 피폐하여 빈부의 격차가 커지게 된다고 생각하였기 때문이다. 더욱이 당시 사회에서는 직업적인 차별이 있어 상공업자들이 제대로 대우받지 못하였다.\n" +
2861 "[편집]\n" +
2862 "초기 조선의 사회\n" +
2863 …다. 양인은 과거에 응시하고 벼슬길에 오를 수 있는 자유민으로서 조세, 국역 등의 의무를 지녔다. 천민은 비(非)자유민으로서 개인이나 국가에 소속되어 천역을 담당하였다.\n" +
2864 … 신분층으로 정착되어 갔다. 그리하여 지배층인 양반과 피지배층인 상민 간의 차별을 두는 반상 제도가 일반화되고 양반, 중인, 상민, 천민의 신분 제도가 점차 정착되었다.\n" +
2865 …가능하였다. 법적으로 양인 이상이면 누구나 과거에 응시하여 관직에 오를 수 있었고, 양반도 죄를 지으면 노비가 되거나 경제적으로 몰락하여 중인이나 상민이 되기도 하였다.\n" +
2866 "[편집]\n" +
2867 "초기 조선의 문화\n" +
2868 …민생 안정과 부국강병을 위하여 과학 기술과 실용적 학문을 중시하여, 한글이 창제되고 역사책을 비롯한 각 분야의 서적들이 출반되는 등 민족 문화 발전의 기반이 형성되었다.\n" +
2869 …이외의 학문과 사상이라도 좋은 점이 있으면 받아들이는 융통성을 보였다. 불교는 정부에 의하여 정비되면서 위축되었으나 민간에서는 여전히 신앙의 대상으로 자리 잡고 있었다.\n" +
2870 "천문학, 의학 등 과학 기술에 있어서도 큰 발전을 이룩하여 생활에 응용되었고, 농업 기술은 크게 향상되어 농업 생산력을 증대시켰다.\n" +
2871 "예술 분야에서도 민족적 특색이 돋보이는 발전을 나타내었고, 사대부들의 검소하고 소박한 생활이 반영된 그림과 필체 및 자기 공예가 두드러졌다.\n" +
2872 "[편집]\n" +
2873 "근대 태동기 (A.D. 1506년 ~ A.D. 1907년)\n" +
2874 "\n" +
2875 "한국사에서는 후기 조선 시대를 근대 태동기로 보고 있다.\n" +
2876 "[편집]\n" +
2877 "후기 조선의 정치\n" +
2878 …평 정치를 추진하였다. 탕평 정치는 특정 권력 집단을 억제하고 왕권을 강화하려는 방향으로 진행되어 어느 정도 성과를 거두었지만, 붕당 정치의 폐단을 일소하지는 못하였다.\n" +
2879 …실의 외척을 중심으로 한 소수 가문에 권력이 집중되고 정치 기강이 문란해지는 세도 정치가 전개되었다. 이로써 부정부패가 만연해지고 정부의 백성들에 대한 수탈이 심해졌다.\n" +
2880 "[편집]\n" +
2881 "후기 조선의 경제\n" +
2882 …는 황폐화되었다. 이에 정부는 수취 체제를 개편하여 농촌 사회를 안정시키고 재정 기반을 확대하려 하였다. 그것은 전세 제도, 공납 제도, 군역 제도의 개편으로 나타났다.\n" +
2883 … 생산도 활발해져 민간에서 생산 활동을 주도하여 갔다. 이러한 과정에서 자본 축적이 이루어지고, 지방의 상공업 활동이 활기를 띠었으며, 상업 도시가 출현하기에 이르렀다.\n" +
2884 "[편집]\n" +
2885 "후기 조선의 사회\n" +
2886 … 경향을 보였다. 이는 부를 축적한 농민들이나 해방된 노비들이 자신들의 지위를 높이기 위하여 또는 역의 부담을 모면하기 위하여 양반 신분을 사는 경우가 많았기 때문이다.\n" +
2887 … 되었다. 정부는 로마 가톨릭이 점차 교세가 확장되자 양반 중심의 신분 질서 부정과 왕권에 대한 도전으로 받아들여[출처 필요] 사교로 규정하고 탄압을 가하기에 이르렀다.\n" +
2888 "[편집]\n" +
2889 "후기 조선의 문화\n" +
2890 …의 변화와 함께 문화에서는 새로운 기운이 나타났다. 양반층 뿐만 아니라 중인층과 서민층도 문화의 한 주역으로 등장하면서 문화의 질적 변화와 함께 문화의 폭이 확대되었다.\n" +
2891 …천성을 강조한 양명학을 받아들였으며 민생 안정과 부국강병을 목표로 하여 비판적이면서 실증적인 논리로 사회 개혁론을 제시한 실학이 대두되어 개혁 추진을 주장하기도 하였다.\n" +
2892 "천문학의 의학 등 각 분야의 기술적 성과들이 농업과 상업 등 산업 발전을 촉진하였다. 서양 문물의 유입도 이러한 발전을 가속화하는 데 이바지하였다.\n" +
2893 …음악 등 서민 문화가 크게 유행하였고, 백자 등 공예도 생활 공예가 중심이 되었다. 자연 경치와 삶을 소재로 하는 문예 풍토가 진작되어 문학과 서화에 큰 영향을 끼쳤다.\n" +
2894 "[편집]\n" +
2895 "근현대시대 (A.D. 1907년 ~ )\n" +
2896 "\n" +
2897 "[편집]\n" +
2898 "개괄\n" +
2899 … 열강에 문호를 개방하였다. 이후 정부와 각계(各界), 각당(各堂), 각단체(各單體), 각층(各層), 각파(各派)에서는 근대화하려는 노력을 하였으나, 성공하지 못하였다.\n" +
2900 …용하고 새로운 경제 정책을 펼치면서 자주적인 근대화를 모색하였다. 그러나 일본과 청을 비롯한 외세의 경제 침략이 본격화 되면서, 이러한 노력은 큰 성과를 거두지 못했다.\n" +
2901 …되면서 신분 제도가 폐지되고 평등 의식도 점차 성장하였다. 또, 외국과의 교류를 통해 외래 문물과 제도 등이 수용됨에 따라 전통적인 생활 모습에도 많은 변화가 생겨났다.\n" +
2902 …아지자, 전기, 철도, 같은 근대 기술과 서양 의술 등 각종 근대 문물이 들어왔다. 근대 시설은 일상생활을 편리하게 해 주었으나, 열강의 침략 목적에 이용되기도 하였다.\n" +
2903 …립 투쟁, 민족 실력 양성 운동, 독립 외교 활동 등을 벌여 일제에 줄기차게 저항하였다. 이러한 우리 민족의 투쟁과 연합군의 승리로 1945년 8월에 광복을 맞이하였다.\n" +
2904 …을 겪게 되었다. 광복 이후 일제의 식민 지배를 벗어나면서부터는 새로운 경제 발전의 계기를 마련할 수 있었다. 그러나 분단과 전쟁으로 인한 경제적 어려움도 대단히 컸다.\n" +
2905 …이 펼쳐졌다. 이러한 가운데 근대 자본주의 문명이 본격적으로 유입되어 전통 사회는 점차 근대 사회로 변모해 갔는데, 식민지 현실 아래에서 근대화는 왜곡될 수밖에 없었다.\n" +
2906 …국 신민화를 강력하게 추진하였다. 특히, 우리 민족의 독립 의지를 꺾으려고 우리의 역사와 문화를 왜곡하였다. 이에 맞서 우리의 전통과 문화를 지키려는 움직임이 일어났다.\n" +
2907 …책과 좌∙우익 세력의 갈등으로 남북이 분단되어 통일 국가를 세우지 못하였다. 특히, 6∙25 전쟁을 겪으면서 분단은 더욱 고착화되고 남북 사이의 상호 불신이 깊어 갔다.\n" +
2908 …나 4∙19혁명과 5∙18민주화 운동, 6월 민주 항쟁 등으로 민주주의가 점차 발전하였다. 이와 함께, 냉전 체제가 해체되면서 민족 통일을 위한 노력도 계속 되고 있다.\n" +
2909 "1960년대 이후 한국 경제는 비약적인 성장을 일구어 냈다. 한국은 이제 가난한 농업 국가가 아닌, 세계적인 경제 대국으로 변모하고 있다.\n" +
2910 … 발전하면서 사람들의 생활양식과 가치관도 많이 변하였다.1980년대에 진행된 민주화 운동으로 권위주의적 정치 문화가 점차 극복되고, 사회의 민주화도 꾸준히 이루어 졌다.\n" +
2911 … 학문 활동이 활발해지고 교육의 기회가 크게 확대되었다. 그러나 미국을 비롯한 서구 문화가 급속하게 유입되면서 가치관의 혼란과 전통문화의 위축 현상을 가져오기도 하였다.\n" +
2912 …체 등 몇몇 과학 기술 분야는 세계적인 수준까지 도달하였다. 한편, 현대 사회의 윤리와 생명 과학 기술의 발달 사이에서 빚어지는 갈등을 해소하려는 노력도 펼쳐지고 있다.\n" +
2913 "[편집]\n" +
2914 "근대시대\n" +
2915 "대한 제국\n" +
2916 "일제강점기 : 일본의 제국주의 세력이 한반도를 강제적으로 식민지로 삼은 시기로서, 무단 통치 시기, 문화 통치 시기, 전시 체계 시기로 나뉜다.\n" +
2917 …회사령을 공포하여 국내의 자본 세력을 억압하고 일본 자본 세력의 편의를 봐주었다. 이 시기의 한국인 노동자는 극악한 환경과 저임금, 민족적 차별까지 받으며 혹사 하였다.\n" +
2918 …기회를 늘리고 자본 운용의 기회와 참정권의 기회등을 제공하겠다고 선전 하였으나 소수의 친일 분자를 육성하고, 민족 운동가들을 회유하여 민족을 기만하고 분열을 획책하였다.\n" +
2919 … 동원하였다. 또, 젊은 여성을 정신대라는 이름으로 강제 동원하여 군수 공장 등에서 혹사시켰으며, 그 중 일부는 전선으로 끌고 가 일본군 위안부로 삼는 만행을 저질렀다.\n" +
2920 "[편집]\n" +
2921 "현대시대\n" +
2922 "군정기 : 미국과 소련의 군대가 진주하여 한반도에 정부가 세워지기 이전까지의 시기\n" +
2923 "대한민국\n" +
2924 "제1공화국\n" +
2925 "한국전쟁\n" +
2926 "제2공화국\n" +
2927 "제3공화국\n" +
2928 "제4공화국 - 유신헌법시기. 종신 대통령제 채택\n" +
2929 "제5공화국\n" +
2930 …택. 이 시기에는 민주화에 대한 무자비한 탄압이 자행되었으나, 광범위한 대중들의 1987년 6월 혁명으로 6월29선언(대통령 직접선거제도 공약)을 이끌어 내기도 하였다.\n" +
2931 …중공업, 경공업 기반을 첨단공업 수준으로 이끌어 올린 시기이다. 이 시기의 한국 경제는 세계에서 유래 없을 정도로 빠르게 성장했으며, 국내 물가가 가장 안정된 시기였다.\n" +
2932 "3. 문화 : 1986년 서울 아시안 게임을 개최하였고, 1988년 서울 올림픽 게임을 유치하는 데 성공했다.\n" +
2933 "제6공화국\n" +
2934 "노태우 정권\n" +
2935 "문민정부\n" +
2936 "국민의 정부\n" +
2937 "참여정부\n" +
2938 "조선민주주의인민공화국\n" +
2939 "조선민주주의인민공화국의 역사\n" +
2940 "[편집]\n" +
2941 "주석\n" +
2942 "\n" +
2943 "↑ 삼국유사 - 동경제국대학 1904년 판본, 환단고기 - 1979년 복원본\n" +
2944 "↑ 동사 - 허목 숙종조, 규원사화 - 북애자 숙종원년\n" +
2945 "↑ 환단고기 - 1979년 복원본\n" +
2946 "[편집]\n" +
2947 "같이 보기\n" +
2948 "\n" +
2949 "중국의 역사\n" +
2950 "일본의 역사\n" +
2951 "민족사관\n" +
2952 "식민사관\n" +
2953 "[편집]\n" +
2954 "참고문헌 및 링크\n" +
2955 "\n" +
2956 "[편집]\n" +
2957 "역사 일반\n" +
2958 …한국사에 관한 정보를 수집, 정리, 편찬하는 국가 연구 기관, 소장 자료, 논문, 저서 검색, 한국사 관련 연구 기관. 소장 자료, 논문, 저서 검색, 한국사 관련 안내\n" +
2959 "국사 전자 교과서 : 현직 교사들이 연구.감수하고, 국사편찬위원회가 지원하였다. 2007년 개정된 국사교과서의 내용이 아직 반영되지 않았다.\n" +
2960 "한국 역사 정보 시스템 : 한국사 연표, 한국사 기초 사전 및 신문 자료, 문헌 자료, 문집 등을 제공\n" +
2961 "한국학 중앙 연구원 : 한국 문화 및 한국학 여러 분햐에 관한 연구와 교육을 수행하는 연구 기관. 디지털 한국학 개발, 정보 광장, 전자 도서관, 전통 문화 등 수록\n" +
2962 "역사 문제 연구소 : 순수 민간 연구 단체(역사적 중립성이 의심됨), 근현대사 자료실, 간행물 자료, 한국사 학습 자료 등 수록\n" +
2963 "[편집]\n" +
2964 "재단, 기타, 정부 기관\n" +
2965 …여 2004年 설립된 법인. 고구려, 발해를 비롯한 동아시아 역사 관련 자료의 조사, 수집, 정리, 정보화 자료 제공. 동북아역사재단으로 편입되어 더이상 유용하지 않다.\n" +
2966 "국가 기록 영상관 : 대한 뉴스, 문화 기록 영화, 대통령 기록 영상 등 멀티미디어 역사 자료 제공\n" +
2967 "국가 문화 유산 종합 정보 서비스 : 국보, 보물, 사적, 명승, 천연 기념물 지정 종목별, 시대별, 지역별, 유형별, 유물 정보, 검색 서비스 제공\n" +
2968 "국가 지식 정보 통합 검색 시스템 : 정보 통신부 제공, 과학 기술, 정보 통신, 교육, 학술, 문화, 역사 등의 포괄적이고 연동적인 학술 데이터 검색\n" +
2969 "국가기록유산 : 국가적 기록유산의 원본과 원문 열람 서비스 제공\n";
2973 "تاریخ ایران پیش از اسلام\n" +
2974 "از ویکیپدیا، دانشنامهٔ آزاد.\n" +
2975 "تمدنهای باستانی آسیای غربی\n" +
2976 "بینالنهرین، سومر، اکد، آشور، بابل\n" +
2977 "هیتیها، لیدیه\n" +
2978 "ایلام، اورارتو، ماننا، ماد، هخامنشی\n" +
2979 "امپراتوریها / شهرها\n" +
2980 "سومر: اوروک – اور – اریدو\n" +
2981 "کیش – لاگاش – نیپور – اکد\n" +
2982 "بابل – ایسین – کلدانی\n" +
2983 "آشور: آسور، نینوا، نوزی، نمرود\n" +
2984 "ایلامیان – اموریها – شوش\n" +
2985 "هوریها – میتانی\n" +
2986 "کاسیها – اورارتو\n" +
2987 "گاهشماری\n" +
2988 "شاهان سومر\n" +
2989 "شاهان ایلام\n" +
2990 "شاهان آشور\n" +
2991 "شاهان بابل\n" +
2992 "شاهان ماد\n" +
2993 "شاهان هخامنشی\n" +
2994 "زبان\n" +
2995 "خط میخی\n" +
2996 "سومری – اکدی\n" +
2997 "ایلامی – هوری\n" +
2998 "اساطیر بینالنهرین\n" +
2999 "انوما الیش\n" +
3000 "گیل گمش – مردوخ\n" +
3001 "نیبیرو\n" +
3002 … امروز) بجای مانده است. اما تمدن این اقوام کم کم با ورود آریائیان، در فرهنگ و تمدن آنها حل شد.\n" +
3003 …مناطق ایران در رابطه با تمدنهای دیگر نظیر سومر - اکد، کلده - بابل - آشور، و غیره نیز مهم است.\n" +
3004 "فهرست مندرجات [مخفی شود]\n" +
3005 "۱ ایلامیان\n" +
3006 "۲ مهاجرت آریائیان به ایران\n" +
3007 "۳ مادها\n" +
3008 "۴ هخامنشیان\n" +
3009 "۵ سلوکیان\n" +
3010 "۶ اشکانیان\n" +
3011 "۷ ساسانیان\n" +
3012 "۸ منابع\n" +
3013 "۹ جستارهای وابسته\n" +
3014 "۱۰ پیوند به بیرون\n" +
3015 "[ویرایش]\n" +
3016 "ایلامیان\n" +
3017 "\n" +
3018 …های خوزستان، فارس، ایلام و بخشهایی از استانهای بوشهر، کرمان، لرستان و کردستان را شامل میشد.\n" +
3019 …سند هند و از راه شوش با تمدن سومر مربوط میشده است. ایلامیان نخستین مخترعان خط در ایران هستند.\n" +
3020 …د. تا پیش از ورود مادها و پارسها حدود یك هزار سال تاریخ سرزمین ایران منحصر به تاریخ عیلام است.\n" +
3021 …هر اثر گذار بوده است. عیلامیان نه سامی نژادند و نه آریایی آنان ساكنان اوليه دشت خوزستان هستند.\n" +
3022 "[ویرایش]\n" +
3023 "مهاجرت آریائیان به ایران\n" +
3024 "\n" +
3025 … در پایان دوران نوسنگی (7000 سال پیش از میلاد) آغاز شد و تا 4000 پیش از میلاد ادامه داشته است.\n" +
3026 … سکنی گزیدند: مادها در شمال غربی ایران، پارسها در قسمت جنوبی و پارتها در حدود خراسان امروزی.\n" +
3027 …زمانی برای خودشان اتحادیههای قبایلی و امیرنشین داشتهاند، و سپس در پادشاهی ماد ادغام شدهاند.\n" +
3028 …یب پانصد سال (250 ق.م – 226 م) و ساسانیان قریب چهار صد و سی سال (226-651 م) فرمانروایی داشتند.\n" +
3029 "[ویرایش]\n" +
3030 "مادها\n" +
3031 "\n" +
3032 "\n" +
3033 "\n" +
3034 "ماد در 675 پیش از میلاد\n" +
3035 "\n" +
3036 "\n" +
3037 "ماد در 600 پیش از میلاد\n" +
3038 …ت ماد هگمتانه است آنها توانستند در اوایل قرن هفتم قبل از میلاد اولین دولت ایرانی را تأسیس کنند\n" +
3039 …ات شدید و خونین آشوریان به مناطق مادنشین، گروهی از بزرگان ماد گرد رهبری به نام دیاکو جمع شدند.\n" +
3040 …م امپراتوری آشور را منقرض کرد و پایههای نخستین شاهنشاهی آریاییتباران در ایران را بنیاد نهاد.\n" +
3041 …ی هخامنشی به منتهای بزرگی خود رسید: از هند تا دریای آدریاتیک و از دریای عمان تا کوههای قفقاز.\n" +
3042 "[ویرایش]\n" +
3043 "هخامنشیان\n" +
3044 "\n" +
3045 "\n" +
3046 "\n" +
3047 "شاهنشاهی بزرگ هخامنشی در 330 ق.م.\n" +
3048 …نشیان تبدیل به شاهنشاهی بزرگی شد. از این رو کوروش بزرگ را بنیادگذار شاهنشاهی هخامنشی میدانند.\n" +
3049 …یوش بزرگ در کتیبهً بیستون میگوید: \" بعد از رفتن او (کمبوجیه) به مصر مردم از او برگشتند...\"\n" +
3050 …نستان (مکائیه).\" داریوش از 9 مهر ماه 522 تا 19 اسفند 520 ق.م به سرکوبی این جنبشها مشغول بود.\n" +
3051 …ت هخامنشی سر انجام در 330 ق. م به دست اسکندر مقدونی منقرض گشت و ایران به دست سپاهیان او افتاد.\n" +
3052 … را سرکوب کردند ولی از این تاریخ اسکندر ناچار روش خشونت آمیز خود را به نرمش و خوشخویی بدل کرد.\n" +
3053 "\n" +
3054 "ایران\n" +
3055 "تاریخ ایران\n" +
3056 "ایران پیش از آریاییها \n" +
3057 "تاریخ ایران پیش از اسلام \n" +
3058 " | دودمانها و حکومتها\n" +
3059 "ایلامیان\n" +
3060 "ماد\n" +
3061 "هخامنشیان\n" +
3062 "سلوکیان\n" +
3063 "اشکانیان\n" +
3064 "ساسانیان\n" +
3065 "تاریخ ایران پس از اسلام \n" +
3066 " | دودمانها و حکومتها\n" +
3067 "خلفای راشدین\n" +
3068 "امویان\n" +
3069 "عباسیان\n" +
3070 "ایران در دوران حکومتهای محلی \n" +
3071 " | دودمانها و حکومتها\n" +
3072 "طاهریان\n" +
3073 "صفاریان\n" +
3074 "سامانیان\n" +
3075 "آل زیار\n" +
3076 "آل بویه\n" +
3077 "غزنویان\n" +
3078 "سلجوقیان\n" +
3079 "خوارزمشاهیان\n" +
3080 "ایران در دوره مغول \n" +
3081 " | دودمانها و حکومتها\n" +
3082 "ایلخانیان\n" +
3083 "ایران در دوران ملوکالطوایفی \n" +
3084 " | دودمانها و حکومتها\n" +
3085 "سربداران\n" +
3086 "تیموریان\n" +
3087 "مرعشیان\n" +
3088 "کیائیان\n" +
3089 "قراقویونلو\n" +
3090 "آققویونلو\n" +
3091 "ایران در دوران حکومتهای ملی \n" +
3092 " | دودمانها و حکومتها\n" +
3093 "صفوی\n" +
3094 "افشاریان\n" +
3095 "زند\n" +
3096 "قاجار\n" +
3097 "پهلوی\n" +
3098 "جمهوری اسلامی\n" +
3099 "موضوعی\n" +
3100 "تاریخ معاصر ایران\n" +
3101 "تاریخ مذاهب ایران\n" +
3102 "مهرپرستی\n" +
3103 "زرتشتی\n" +
3104 "تسنن\n" +
3105 "تصوف\n" +
3106 "تشیع\n" +
3107 "تاریخ اسلام\n" +
3108 "تاریخ زبان و ادبیات ایران\n" +
3109 "جغرافیای ایران\n" +
3110 "استانهای تاریخی ایران\n" +
3111 "اقتصاد ایران\n" +
3112 "گاهشمار تاریخ ایران\n" +
3113 "پروژه ایران\n" +
3114 "[ویرایش]\n" +
3115 "سلوکیان\n" +
3116 "\n" +
3117 "\n" +
3118 "ایران در زمان سلوکیان (330 - 150 ق.م.)\n" +
3119 … نفوذ خود را گسترش دادند و سرانجام توانستند سلوکیان را نابود و امپراتوری اشکانی را ایجاد کنند.\n" +
3120 "[ویرایش]\n" +
3121 "اشکانیان\n" +
3122 "\n" +
3123 "\n" +
3124 "\n" +
3125 "امپراتوری اشکانی 250 ق.م. 224 م.\n" +
3126 … دریای خزر میزیستند در یک جا سکونت داشتند و سپس از آنان جدا شده در ناحیه خراسان مسکن گزیدند.\n" +
3127 …لافات داخلی و جنگهای خارجی به تدریج ضعیف شد تا سر انجام به دست اردشیر اول ساسانی منقرض گردید.\n" +
3128 "[ویرایش]\n" +
3129 "ساسانیان\n" +
3130 "\n" +
3131 "\n" +
3132 "\n" +
3133 "شاهنشاهی ساسانی در سالهای ۲۲۴ تا ۶۵۱ م.\n" +
3134 …از غرب قارهٔ آسیا چیرگی یافتند. پایتخت ساسانیان شهر تیسفون در نزدیکی بغداد در عراق امروزی بود.\n" +
3135 … و تمدن ایرانی بود و قدرت بسیار زیادی کسب کرد. در این دوره نیز جنگهای ایران و روم ادامه یافت.\n" +
3136 "\n" +
3137 … را به راه \"معنویت\" و \"آشتیخواهی\" سوق میداد و از جانب دیگر از قدرت مذهب زردشت میکاست.\n" +
3138 … کشتند. مانویان درد و جانب شرق و غرب، در آسیای میانه تا سرحد چین و در غرب تا روم پراکنده شدند.\n" +
3139 "\n" +
3140 … را در جنگهای قادسیه، مدائن، جلولاء و نهاوند شکست دادند و بدین ترتیب دولت ساسانی از میان رفت.\n" +
3141 …صورت قیامی واقعی سی سال ( 24-494 م.) دوام آورد و تأثیر شگرفی در تکامل جامعه آن روزایران بخشید.\n" +
3142 …ب خود که گویند موسسش زردشت خورک بابوندس بوده، پرداخت. عقاید مزدک بر دو گانگی مانوی استوار است:\n" +
3143 …کی با عقل و بدی جاهل، این دو نیرو با هم در نبردند و چون روشنائی داناست سرانجام پیروز خواهد شد.\n" +
3144 "اساس تعلیمات اجتماعی مزدک دو چیز است: یکی برابری و دیگری دادگری.\n" +
3145 …ب شد، اما افکار او اثر خود را حتی در قیامها و جنبشهای مردم ایران در دوران اسلام، باقی گذاشت.\n" +
3146 "[ویرایش]\n" +
3147 "منابع\n" +
3148 "\n" +
3149 "تاریخ ایران - دکتر خنجی\n" +
3150 "تاریخ اجتماعی ایران. مرتضی راوندی. ( جلد ۱ ) 1354\n" +
3151 "تاریخ ماد. ایگور میخائیلوویچ دیاکونوف. ترجمه کریم کشاورز، تهران: نشر امیرکبیر.\n" +
3152 … ايران باستان. دياكونوف، ميخائيل ميخائيلوويچ. روحی ارباب. انتشارات علمی و فرهنگی، چاپ دوم 1380\n" +
3153 "سهم ایرانیان در پیدایش و آفرینش خط در جهان ،دکتر رکن الدین همایونفرخ، انتشارات اساطیر.\n" +
3154 "کمرون، جرج. ایران در سپیده دم تاریخ. ترجمه حسن انوشه. تهران، مرکز نشر دانشگاهی، 1379\n" +
3155 … باستان تا امروز، ا. آ. گرانتوسكی - م. آ. داندامایو، مترجم، كیخسرو كشاورزی، ناشر: مرواريد 1385\n" +
3156 "تاریخ ایران از عهد باستان تا قرن 18، پیگولووسکایا، ترجمه کریم کشاورز، تهران، 1353.\n" +
3157 "[ویرایش]\n" +
3158 "جستارهای وابسته\n" +
3159 "\n" +
3160 "ماد\n" +
3161 "کاسی\n" +
3162 "ایلامیان\n" +
3163 "تپه هگمتانه\n" +
3164 "تاریخ ایران\n" +
3165 "ایران پیش از آریاییها\n" +
3166 "تمدنهای باستانی آسیای غربی\n" +
3167 "[ویرایش]\n" +
3168 "پیوند به بیرون\n" +
3169 "\n" +
3170 "ایران قبل از آریاها\n" +
3171 "ايران پيش از آرياییها\n" +
3172 "تمدنهای قبل از آریایی ایران\n" +
3173 "ایران ازدیدگاه باستانشناسی\n" +
3174 "سنگنبشتهی داریوش بزرگ در بیستون\n" +
3175 "شیوه آسیائی تولید در ایران\n" +
3176 "نیای اساطیری ایرانیان\n" +
3177 "قیامهای ایرانیان در طول تاریخ\n" +
3178 "خلاصهٔ تاریخ ایران\n" +
3179 "شهر، شهرسازی و شهرنشينی در ايران پيش از اسلام\n" +
3180 "\n" +
3181 "[3]\n" +
3182 "[4]\n" +
3183 "[5]\n" +
3184 "[6]\n" +
3185 "[7]\n" +
3186 "\n" +
3187 "\n" +
3188 "\n" +
3189 " این نوشتار خُرد است. با گسترش آن به ویکیپدیا کمک کنید.\n" +
3190 "\n" +
3191 …نمای ویرایش و شیوهنامه آن را تغییر دهید. در پایان، پس از ویکیسازی این الگوی پیامی را بردارید.\n";
3195 ("/*\n" +
3196 " This is a version (aka dlmalloc) of malloc/free/realloc written by\n" +
3197 " Doug Lea and released to the public domain. Use, modify, and\n" +
3198 " redistribute this code without permission or acknowledgement in any\n" +
3199 " way you wish. Send questions, comments, complaints, performance\n" +
3200 " data, etc to dl@cs.oswego.edu\n" +
3201 "\n" +
3202 "* VERSION 2.7.2 Sat Aug 17 09:07:30 2002 Doug Lea (dl at gee)\n" +
3203 "\n" +
3204 " Note: There may be an updated version of this malloc obtainable at\n" +
3205 " ftp://gee.cs.oswego.edu/pub/misc/malloc.c\n" +
3206 " Check before installing!\n" +
3207 "\n" +
3208 "* Quickstart\n" +
3209 "\n" +
3210 " This library is all in one file to simplify the most common usage:\n" +
3211 " ftp it, compile it (-O), and link it into another program. All\n" +
3212 " of the compile-time options default to reasonable values for use on\n" +
3213 " most unix platforms. Compile -DWIN32 for reasonable defaults on windows.\n" +
3214 " You might later want to step through various compile-time and dynamic\n" +
3215 " tuning options.\n" +
3216 "\n" +
3217 " For convenience, an include file for code using this malloc is at:\n" +
3218 " ftp://gee.cs.oswego.edu/pub/misc/malloc-2.7.1.h\n" +
3219 " You don't really need this .h file unless you call functions not\n" +
3220 " defined in your system include files. The .h file contains only the\n" +
3221 " excerpts from this file needed for using this malloc on ANSI C/C++\n" +
3222 " systems, so long as you haven't changed compile-time options about\n" +
3223 " naming and tuning parameters. If you do, then you can create your\n" +
3224 " own malloc.h that does include all settings by cutting at the point\n" +
3225 " indicated below.\n" +
3226 "\n" +
3227 "* Why use this malloc?\n" +
3228 "\n" +
3229 " This is not the fastest, most space-conserving, most portable, or\n" +
3230 " most tunable malloc ever written. However it is among the fastest\n" +
3231 " while also being among the most space-conserving, portable and tunable.\n" +
3232 " Consistent balance across these factors results in a good general-purpose\n" +
3233 " allocator for malloc-intensive programs.\n" +
3234 "\n" +
3235 " The main properties of the algorithms are:\n" +
3236 " * For large (>= 512 bytes) requests, it is a pure best-fit allocator,\n" +
3237 " with ties normally decided via FIFO (i.e. least recently used).\n" +
3238 " * For small (<= 64 bytes by default) requests, it is a caching\n" +
3239 " allocator, that maintains pools of quickly recycled chunks.\n" +
3240 " * In between, and for combinations of large and small requests, it does\n" +
3241 " the best it can trying to meet both goals at once.\n" +
3242 " * For very large requests (>= 128KB by default), it relies on system\n" +
3243 " memory mapping facilities, if supported.\n" +
3244 "\n" +
3245 " For a longer but slightly out of date high-level description, see\n" +
3246 " http://gee.cs.oswego.edu/dl/html/malloc.html\n" +
3247 "\n" +
3248 " You may already by default be using a C library containing a malloc\n" +
3249 " that is based on some version of this malloc (for example in\n" +
3250 " linux). You might still want to use the one in this file in order to\n" +
3251 " customize settings or to avoid overheads associated with library\n" +
3252 " versions.\n" +
3253 "\n" +
3254 "* Contents, described in more detail in \"description of public routines\" below.\n" +
3255 "\n" +
3256 " Standard (ANSI/SVID/...) functions:\n" +
3257 " malloc(size_t n);\n" +
3258 " calloc(size_t n_elements, size_t element_size);\n" +
3259 " free(Void_t* p);\n" +
3260 " realloc(Void_t* p, size_t n);\n" +
3261 " memalign(size_t alignment, size_t n);\n" +
3262 " valloc(size_t n);\n" +
3263 " mallinfo()\n" +
3264 " mallopt(int parameter_number, int parameter_value)\n" +
3265 "\n" +
3266 " Additional functions:\n" +
3267 " independent_calloc(size_t n_elements, size_t size, Void_t* chunks[]);\n" +
3268 " independent_comalloc(size_t n_elements, size_t sizes[], Void_t* chunks[]);\n" +
3269 " pvalloc(size_t n);\n" +
3270 " cfree(Void_t* p);\n" +
3271 " malloc_trim(size_t pad);\n" +
3272 " malloc_usable_size(Void_t* p);\n" +
3273 " malloc_stats();\n" +
3274 "\n" +
3275 "* Vital statistics:\n" +
3276 "\n" +
3277 " Supported pointer representation: 4 or 8 bytes\n" +
3278 " Supported size_t representation: 4 or 8 bytes\n" +
3279 " Note that size_t is allowed to be 4 bytes even if pointers are 8.\n" +
3280 " You can adjust this by defining INTERNAL_SIZE_T\n" +
3281 "\n" +
3282 " Alignment: 2 * sizeof(size_t) (default)\n" +
3283 " (i.e., 8 byte alignment with 4byte size_t). This suffices for\n" +
3284 " nearly all current machines and C compilers. However, you can\n" +
3285 " define MALLOC_ALIGNMENT to be wider than this if necessary.\n" +
3286 "\n" +
3287 " Minimum overhead per allocated chunk: 4 or 8 bytes\n" +
3288 " Each malloced chunk has a hidden word of overhead holding size\n" +
3289 " and status information.\n" +
3290 "\n" +
3291 " Minimum allocated size: 4-byte ptrs: 16 bytes (including 4 overhead)\n" +
3292 " 8-byte ptrs: 24/32 bytes (including, 4/8 overhead)\n" +
3293 "\n" +
3294 " When a chunk is freed, 12 (for 4byte ptrs) or 20 (for 8 byte\n" +
3295 " ptrs but 4 byte size) or 24 (for 8/8) additional bytes are\n" +
3296 " needed; 4 (8) for a trailing size field and 8 (16) bytes for\n" +
3297 " free list pointers. Thus, the minimum allocatable size is\n" +
3298 " 16/24/32 bytes.\n" +
3299 "\n" +
3300 " Even a request for zero bytes (i.e., malloc(0)) returns a\n" +
3301 " pointer to something of the minimum allocatable size.\n" +
3302 "\n" +
3303 " The maximum overhead wastage (i.e., number of extra bytes\n" +
3304 " allocated than were requested in malloc) is less than or equal\n" +
3305 " to the minimum size, except for requests >= mmap_threshold that\n" +
3306 " are serviced via mmap(), where the worst case wastage is 2 *\n" +
3307 " sizeof(size_t) bytes plus the remainder from a system page (the\n" +
3308 " minimal mmap unit); typically 4096 or 8192 bytes.\n" +
3309 "\n" +
3310 " Maximum allocated size: 4-byte size_t: 2^32 minus about two pages\n" +
3311 " 8-byte size_t: 2^64 minus about two pages\n" +
3312 "\n" +
3313 " It is assumed that (possibly signed) size_t values suffice to\n" +
3314 " represent chunk sizes. `Possibly signed' is due to the fact\n" +
3315 " that `size_t' may be defined on a system as either a signed or\n" +
3316 " an unsigned type. The ISO C standard says that it must be\n" +
3317 " unsigned, but a few systems are known not to adhere to this.\n" +
3318 " Additionally, even when size_t is unsigned, sbrk (which is by\n" +
3319 " default used to obtain memory from system) accepts signed\n" +
3320 " arguments, and may not be able to handle size_t-wide arguments\n" +
3321 " with negative sign bit. Generally, values that would\n" +
3322 " appear as negative after accounting for overhead and alignment\n" +
3323 " are supported only via mmap(), which does not have this\n" +
3324 " limitation.\n" +
3325 "\n" +
3326 " Requests for sizes outside the allowed range will perform an optional\n" +
3327 " failure action and then return null. (Requests may also\n" +
3328 " also fail because a system is out of memory.)\n" +
3329 "\n" +
3330 " Thread-safety: NOT thread-safe unless USE_MALLOC_LOCK defined\n" +
3331 "\n" +
3332 " When USE_MALLOC_LOCK is defined, wrappers are created to\n" +
3333 " surround every public call with either a pthread mutex or\n" +
3334 " a win32 spinlock (depending on WIN32). This is not\n" +
3335 " especially fast, and can be a major bottleneck.\n" +
3336 " It is designed only to provide minimal protection\n" +
3337 " in concurrent environments, and to provide a basis for\n" +
3338 " extensions. If you are using malloc in a concurrent program,\n" +
3339 " you would be far better off obtaining ptmalloc, which is\n" +
3340 " derived from a version of this malloc, and is well-tuned for\n" +
3341 " concurrent programs. (See http://www.malloc.de) Note that\n" +
3342 " even when USE_MALLOC_LOCK is defined, you can can guarantee\n" +
3343 " full thread-safety only if no threads acquire memory through\n" +
3344 " direct calls to MORECORE or other system-level allocators.\n" +
3345 "\n" +
3346 " Compliance: I believe it is compliant with the 1997 Single Unix Specification\n" +
3347 " (See http://www.opennc.org). Also SVID/XPG, ANSI C, and probably\n" +
3348 " others as well.\n" +
3349 "\n" +
3350 "* Synopsis of compile-time options:\n" +
3351 "\n" +
3352 " People have reported using previous versions of this malloc on all\n" +
3353 " versions of Unix, sometimes by tweaking some of the defines\n" +
3354 " below. It has been tested most extensively on Solaris and\n" +
3355 " Linux. It is also reported to work on WIN32 platforms.\n" +
3356 " People also report using it in stand-alone embedded systems.\n" +
3357 "\n" +
3358 " The implementation is in straight, hand-tuned ANSI C. It is not\n" +
3359 " at all modular. (Sorry!) It uses a lot of macros. To be at all\n" +
3360 " usable, this code should be compiled using an optimizing compiler\n" +
3361 " (for example gcc -O3) that can simplify expressions and control\n" +
3362 " paths. (FAQ: some macros import variables as arguments rather than\n" +
3363 " declare locals because people reported that some debuggers\n" +
3364 " otherwise get confused.)\n" +
3365 "\n" +
3366 " OPTION DEFAULT VALUE\n" +
3367 "\n" +
3368 " Compilation Environment options:\n" +
3369 "\n" +
3370 " __STD_C derived from C compiler defines\n" +
3371 " WIN32 NOT defined\n" +
3372 " HAVE_MEMCPY defined\n" +
3373 " USE_MEMCPY 1 if HAVE_MEMCPY is defined\n" +
3374 " HAVE_MMAP defined as 1\n" +
3375 " MMAP_CLEARS 1\n" +
3376 " HAVE_MREMAP 0 unless linux defined\n" +
3377 " malloc_getpagesize derived from system #includes, or 4096 if not\n" +
3378 " HAVE_USR_INCLUDE_MALLOC_H NOT defined\n" +
3379 " LACKS_UNISTD_H NOT defined unless WIN32\n" +
3380 " LACKS_SYS_PARAM_H NOT defined unless WIN32\n" +
3381 " LACKS_SYS_MMAN_H NOT defined unless WIN32\n" +
3382 " LACKS_FCNTL_H NOT defined\n" +
3383 "\n" +
3384 " Changing default word sizes:\n" +
3385 "\n" +
3386 " INTERNAL_SIZE_T size_t\n" +
3387 " MALLOC_ALIGNMENT 2 * sizeof(INTERNAL_SIZE_T)\n" +
3388 " PTR_UINT unsigned long\n" +
3389 " CHUNK_SIZE_T unsigned long\n" +
3390 "\n" +
3391 " Configuration and functionality options:\n" +
3392 "\n" +
3393 " USE_DL_PREFIX NOT defined\n" +
3394 " USE_PUBLIC_MALLOC_WRAPPERS NOT defined\n" +
3395 " USE_MALLOC_LOCK NOT defined\n" +
3396 " DEBUG NOT defined\n" +
3397 " REALLOC_ZERO_BYTES_FREES NOT defined\n" +
3398 " MALLOC_FAILURE_ACTION errno = ENOMEM, if __STD_C defined, else no-op\n" +
3399 " TRIM_FASTBINS 0\n" +
3400 " FIRST_SORTED_BIN_SIZE 512\n" +
3401 "\n" +
3402 " Options for customizing MORECORE:\n" +
3403 "\n" +
3404 " MORECORE sbrk\n" +
3405 " MORECORE_CONTIGUOUS 1\n" +
3406 " MORECORE_CANNOT_TRIM NOT defined\n" +
3407 " MMAP_AS_MORECORE_SIZE (1024 * 1024)\n" +
3408 "\n" +
3409 " Tuning options that are also dynamically changeable via mallopt:\n" +
3410 "\n" +
3411 " DEFAULT_MXFAST 64\n" +
3412 " DEFAULT_TRIM_THRESHOLD 256 * 1024\n" +
3413 " DEFAULT_TOP_PAD 0\n" +
3414 " DEFAULT_MMAP_THRESHOLD 256 * 1024\n" +
3415 " DEFAULT_MMAP_MAX 65536\n" +
3416 "\n" +
3417 " There are several other #defined constants and macros that you\n" +
3418 " probably don't want to touch unless you are extending or adapting malloc.\n" +
3419 "*/\n" +
3420 "\n" +
3421 "#define MORECORE_CONTIGUOUS 0\n" +
3422 "#define MORECORE_CANNOT_TRIM 1\n" +
3423 "#define MALLOC_FAILURE_ACTION abort()\n" +
3424 "\n" +
3425 "\n" +
3426 "namespace khtml {\n" +
3427 "\n" +
3428 "#ifndef NDEBUG\n" +
3429 "\n" +
3430 "// In debugging builds, use the system malloc for its debugging features.\n" +
3431 "\n" +
3432 "void *main_thread_malloc(size_t n)\n" +
3433 "{\n" +
3434 " assert(pthread_main_np());\n" +
3435 " return malloc(n);\n" +
3436 "}\n" +
3437 "\n" +
3438 "void *main_thread_calloc(size_t n_elements, size_t element_size)\n" +
3439 "{\n" +
3440 " assert(pthread_main_np());\n" +
3441 " return calloc(n_elements, element_size);\n" +
3442 "}\n" +
3443 "\n" +
3444 "void main_thread_free(void* p)\n" +
3445 "{\n" +
3446 " // it's ok to main_thread_free on a non-main thread - the actual\n" +
3447 " // free will be scheduled on the main thread in that case.\n" +
3448 " free(p);\n" +
3449 "}\n" +
3450 "\n" +
3451 "void *main_thread_realloc(void* p, size_t n)\n" +
3452 "{\n" +
3453 " assert(pthread_main_np());\n" +
3454 " return realloc(p, n);\n" +
3455 "}\n" +
3456 "\n" +
3457 "#else\n" +
3458 "\n" +
3459 "/*\n" +
3460 " WIN32 sets up defaults for MS environment and compilers.\n" +
3461 " Otherwise defaults are for unix.\n" +
3462 "*/\n" +
3463 "\n" +
3464 "/* #define WIN32 */\n" +
3465 "\n" +
3466 "#ifdef WIN32\n" +
3467 "\n" +
3468 "#define WIN32_LEAN_AND_MEAN\n" +
3469 "#include <windows.h>\n" +
3470 "\n" +
3471 "/* Win32 doesn't supply or need the following headers */\n" +
3472 "#define LACKS_UNISTD_H\n" +
3473 "#define LACKS_SYS_PARAM_H\n" +
3474 "#define LACKS_SYS_MMAN_H\n" +
3475 "\n" +
3476 "/* Use the supplied emulation of sbrk */\n" +
3477 "#define MORECORE sbrk\n" +
3478 "#define MORECORE_CONTIGUOUS 1\n" +
3479 "#define MORECORE_FAILURE ((void*)(-1))\n" +
3480 "\n" +
3481 "/* Use the supplied emulation of mmap and munmap */\n" +
3482 "#define HAVE_MMAP 1\n" +
3483 "#define MUNMAP_FAILURE (-1)\n" +
3484 "#define MMAP_CLEARS 1\n" +
3485 "\n" +
3486 "/* These values don't really matter in windows mmap emulation */\n" +
3487 "#define MAP_PRIVATE 1\n" +
3488 "#define MAP_ANONYMOUS 2\n" +
3489 "#define PROT_READ 1\n" +
3490 "#define PROT_WRITE 2\n" +
3491 "\n" +
3492 "/* Emulation functions defined at the end of this file */\n" +
3493 "\n" +
3494 "/* If USE_MALLOC_LOCK, use supplied critical-section-based lock functions */\n" +
3495 "#ifdef USE_MALLOC_LOCK\n") +
3496 ("static int slwait(int *sl);\n" +
3497 "static int slrelease(int *sl);\n" +
3498 "#endif\n" +
3499 "\n" +
3500 "static long getpagesize(void);\n" +
3501 "static long getregionsize(void);\n" +
3502 "static void *sbrk(long size);\n" +
3503 "static void *mmap(void *ptr, long size, long prot, long type, long handle, long arg);\n" +
3504 "static long munmap(void *ptr, long size);\n" +
3505 "\n" +
3506 "static void vminfo (unsigned long*free, unsigned long*reserved, unsigned long*committed);\n" +
3507 "static int cpuinfo (int whole, unsigned long*kernel, unsigned long*user);\n" +
3508 "\n" +
3509 "#endif\n" +
3510 "\n" +
3511 "/*\n" +
3512 " __STD_C should be nonzero if using ANSI-standard C compiler, a C++\n" +
3513 " compiler, or a C compiler sufficiently close to ANSI to get away\n" +
3514 " with it.\n" +
3515 "*/\n" +
3516 "\n" +
3517 "#ifndef __STD_C\n" +
3518 "#if defined(__STDC__) || defined(_cplusplus)\n" +
3519 "#define __STD_C 1\n" +
3520 "#else\n" +
3521 "#define __STD_C 0\n" +
3522 "#endif\n" +
3523 "#endif /*__STD_C*/\n" +
3524 "\n" +
3525 "\n" +
3526 "/*\n" +
3527 " Void_t* is the pointer type that malloc should say it returns\n" +
3528 "*/\n" +
3529 "\n" +
3530 "#ifndef Void_t\n" +
3531 "#if (__STD_C || defined(WIN32))\n" +
3532 "#define Void_t void\n" +
3533 "#else\n" +
3534 "#define Void_t char\n" +
3535 "#endif\n" +
3536 "#endif /*Void_t*/\n" +
3537 "\n" +
3538 "#if __STD_C\n" +
3539 "#include <stddef.h> /* for size_t */\n" +
3540 "#else\n" +
3541 "#include <sys/types.h>\n" +
3542 "#endif\n" +
3543 "\n" +
3544 "/* define LACKS_UNISTD_H if your system does not have a <unistd.h>. */\n" +
3545 "\n" +
3546 "/* #define LACKS_UNISTD_H */\n" +
3547 "\n" +
3548 "#ifndef LACKS_UNISTD_H\n" +
3549 "#include <unistd.h>\n" +
3550 "#endif\n" +
3551 "\n" +
3552 "/* define LACKS_SYS_PARAM_H if your system does not have a <sys/param.h>. */\n" +
3553 "\n" +
3554 "/* #define LACKS_SYS_PARAM_H */\n" +
3555 "\n" +
3556 "\n" +
3557 "#include <stdio.h> /* needed for malloc_stats */\n" +
3558 "#include <errno.h> /* needed for optional MALLOC_FAILURE_ACTION */\n" +
3559 "\n" +
3560 "\n" +
3561 "/*\n" +
3562 " Debugging:\n" +
3563 "\n" +
3564 " Because freed chunks may be overwritten with bookkeeping fields, this\n" +
3565 " malloc will often die when freed memory is overwritten by user\n" +
3566 " programs. This can be very effective (albeit in an annoying way)\n" +
3567 " in helping track down dangling pointers.\n" +
3568 "\n" +
3569 " If you compile with -DDEBUG, a number of assertion checks are\n" +
3570 " enabled that will catch more memory errors. You probably won't be\n" +
3571 " able to make much sense of the actual assertion errors, but they\n" +
3572 " should help you locate incorrectly overwritten memory. The\n" +
3573 " checking is fairly extensive, and will slow down execution\n" +
3574 " noticeably. Calling malloc_stats or mallinfo with DEBUG set will\n" +
3575 " attempt to check every non-mmapped allocated and free chunk in the\n" +
3576 " course of computing the summmaries. (By nature, mmapped regions\n" +
3577 " cannot be checked very much automatically.)\n" +
3578 "\n" +
3579 " Setting DEBUG may also be helpful if you are trying to modify\n" +
3580 " this code. The assertions in the check routines spell out in more\n" +
3581 " detail the assumptions and invariants underlying the algorithms.\n" +
3582 "\n" +
3583 " Setting DEBUG does NOT provide an automated mechanism for checking\n" +
3584 " that all accesses to malloced memory stay within their\n" +
3585 " bounds. However, there are several add-ons and adaptations of this\n" +
3586 " or other mallocs available that do this.\n" +
3587 "*/\n" +
3588 "\n" +
3589 "/*\n" +
3590 " The unsigned integer type used for comparing any two chunk sizes.\n" +
3591 " This should be at least as wide as size_t, but should not be signed.\n" +
3592 "*/\n" +
3593 "\n" +
3594 "#ifndef CHUNK_SIZE_T\n" +
3595 "#define CHUNK_SIZE_T unsigned long\n" +
3596 "#endif\n" +
3597 "\n" +
3598 "/*\n" +
3599 " The unsigned integer type used to hold addresses when they are are\n" +
3600 " manipulated as integers. Except that it is not defined on all\n" +
3601 " systems, intptr_t would suffice.\n" +
3602 "*/\n" +
3603 "#ifndef PTR_UINT\n" +
3604 "#define PTR_UINT unsigned long\n" +
3605 "#endif\n" +
3606 "\n" +
3607 "\n" +
3608 "/*\n" +
3609 " INTERNAL_SIZE_T is the word-size used for internal bookkeeping\n" +
3610 " of chunk sizes.\n" +
3611 "\n" +
3612 " The default version is the same as size_t.\n" +
3613 "\n" +
3614 " While not strictly necessary, it is best to define this as an\n" +
3615 " unsigned type, even if size_t is a signed type. This may avoid some\n" +
3616 " artificial size limitations on some systems.\n" +
3617 "\n" +
3618 " On a 64-bit machine, you may be able to reduce malloc overhead by\n" +
3619 " defining INTERNAL_SIZE_T to be a 32 bit `unsigned int' at the\n" +
3620 " expense of not being able to handle more than 2^32 of malloced\n" +
3621 " space. If this limitation is acceptable, you are encouraged to set\n" +
3622 " this unless you are on a platform requiring 16byte alignments. In\n" +
3623 " this case the alignment requirements turn out to negate any\n" +
3624 " potential advantages of decreasing size_t word size.\n" +
3625 "\n" +
3626 " Implementors: Beware of the possible combinations of:\n" +
3627 " - INTERNAL_SIZE_T might be signed or unsigned, might be 32 or 64 bits,\n" +
3628 " and might be the same width as int or as long\n" +
3629 " - size_t might have different width and signedness as INTERNAL_SIZE_T\n" +
3630 " - int and long might be 32 or 64 bits, and might be the same width\n" +
3631 " To deal with this, most comparisons and difference computations\n" +
3632 " among INTERNAL_SIZE_Ts should cast them to CHUNK_SIZE_T, being\n" +
3633 " aware of the fact that casting an unsigned int to a wider long does\n" +
3634 " not sign-extend. (This also makes checking for negative numbers\n" +
3635 " awkward.) Some of these casts result in harmless compiler warnings\n" +
3636 " on some systems.\n" +
3637 "*/\n" +
3638 "\n" +
3639 "#ifndef INTERNAL_SIZE_T\n" +
3640 "#define INTERNAL_SIZE_T size_t\n" +
3641 "#endif\n" +
3642 "\n" +
3643 "/* The corresponding word size */\n" +
3644 "#define SIZE_SZ (sizeof(INTERNAL_SIZE_T))\n" +
3645 "\n" +
3646 "\n") +
3647 ("\n" +
3648 "/*\n" +
3649 " MALLOC_ALIGNMENT is the minimum alignment for malloc'ed chunks.\n" +
3650 " It must be a power of two at least 2 * SIZE_SZ, even on machines\n" +
3651 " for which smaller alignments would suffice. It may be defined as\n" +
3652 " larger than this though. Note however that code and data structures\n" +
3653 " are optimized for the case of 8-byte alignment.\n" +
3654 "*/\n" +
3655 "\n" +
3656 "\n" +
3657 "#ifndef MALLOC_ALIGNMENT\n" +
3658 "#define MALLOC_ALIGNMENT (2 * SIZE_SZ)\n" +
3659 "#endif\n" +
3660 "\n" +
3661 "/* The corresponding bit mask value */\n" +
3662 "#define MALLOC_ALIGN_MASK (MALLOC_ALIGNMENT - 1)\n" +
3663 "\n" +
3664 "\n" +
3665 "\n" +
3666 "/*\n" +
3667 " REALLOC_ZERO_BYTES_FREES should be set if a call to\n" +
3668 " realloc with zero bytes should be the same as a call to free.\n" +
3669 " Some people think it should. Otherwise, since this malloc\n" +
3670 " returns a unique pointer for malloc(0), so does realloc(p, 0).\n" +
3671 "*/\n" +
3672 "\n" +
3673 "/* #define REALLOC_ZERO_BYTES_FREES */\n" +
3674 "\n" +
3675 "/*\n" +
3676 " TRIM_FASTBINS controls whether free() of a very small chunk can\n" +
3677 " immediately lead to trimming. Setting to true (1) can reduce memory\n" +
3678 " footprint, but will almost always slow down programs that use a lot\n" +
3679 " of small chunks.\n" +
3680 "\n" +
3681 " Define this only if you are willing to give up some speed to more\n" +
3682 " aggressively reduce system-level memory footprint when releasing\n" +
3683 " memory in programs that use many small chunks. You can get\n" +
3684 " essentially the same effect by setting MXFAST to 0, but this can\n" +
3685 " lead to even greater slowdowns in programs using many small chunks.\n" +
3686 " TRIM_FASTBINS is an in-between compile-time option, that disables\n" +
3687 " only those chunks bordering topmost memory from being placed in\n" +
3688 " fastbins.\n" +
3689 "*/\n" +
3690 "\n" +
3691 "#ifndef TRIM_FASTBINS\n" +
3692 "#define TRIM_FASTBINS 0\n" +
3693 "#endif\n" +
3694 "\n" +
3695 "\n" +
3696 "/*\n" +
3697 " USE_DL_PREFIX will prefix all public routines with the string 'dl'.\n" +
3698 " This is necessary when you only want to use this malloc in one part\n" +
3699 " of a program, using your regular system malloc elsewhere.\n" +
3700 "*/\n" +
3701 "\n" +
3702 "#define USE_DL_PREFIX\n" +
3703 "\n" +
3704 "\n" +
3705 "/*\n" +
3706 " USE_MALLOC_LOCK causes wrapper functions to surround each\n" +
3707 " callable routine with pthread mutex lock/unlock.\n" +
3708 "\n" +
3709 " USE_MALLOC_LOCK forces USE_PUBLIC_MALLOC_WRAPPERS to be defined\n" +
3710 "*/\n" +
3711 "\n" +
3712 "\n" +
3713 "/* #define USE_MALLOC_LOCK */\n" +
3714 "\n" +
3715 "\n" +
3716 "/*\n" +
3717 " If USE_PUBLIC_MALLOC_WRAPPERS is defined, every public routine is\n" +
3718 " actually a wrapper function that first calls MALLOC_PREACTION, then\n" +
3719 " calls the internal routine, and follows it with\n" +
3720 " MALLOC_POSTACTION. This is needed for locking, but you can also use\n" +
3721 " this, without USE_MALLOC_LOCK, for purposes of interception,\n" +
3722 " instrumentation, etc. It is a sad fact that using wrappers often\n" +
3723 " noticeably degrades performance of malloc-intensive programs.\n" +
3724 "*/\n" +
3725 "\n" +
3726 "#ifdef USE_MALLOC_LOCK\n" +
3727 "#define USE_PUBLIC_MALLOC_WRAPPERS\n" +
3728 "#else\n" +
3729 "/* #define USE_PUBLIC_MALLOC_WRAPPERS */\n" +
3730 "#endif\n" +
3731 "\n" +
3732 "\n" +
3733 "/*\n" +
3734 " Two-phase name translation.\n" +
3735 " All of the actual routines are given mangled names.\n" +
3736 " When wrappers are used, they become the public callable versions.\n" +
3737 " When DL_PREFIX is used, the callable names are prefixed.\n" +
3738 "*/\n" +
3739 "\n" +
3740 "#ifndef USE_PUBLIC_MALLOC_WRAPPERS\n" +
3741 "#define cALLOc public_cALLOc\n" +
3742 "#define fREe public_fREe\n" +
3743 "#define cFREe public_cFREe\n" +
3744 "#define mALLOc public_mALLOc\n" +
3745 "#define mEMALIGn public_mEMALIGn\n" +
3746 "#define rEALLOc public_rEALLOc\n" +
3747 "#define vALLOc public_vALLOc\n" +
3748 "#define pVALLOc public_pVALLOc\n" +
3749 "#define mALLINFo public_mALLINFo\n" +
3750 "#define mALLOPt public_mALLOPt\n" +
3751 "#define mTRIm public_mTRIm\n" +
3752 "#define mSTATs public_mSTATs\n" +
3753 "#define mUSABLe public_mUSABLe\n" +
3754 "#define iCALLOc public_iCALLOc\n" +
3755 "#define iCOMALLOc public_iCOMALLOc\n" +
3756 "#endif\n" +
3757 "\n" +
3758 "#ifdef USE_DL_PREFIX\n" +
3759 "#define public_cALLOc main_thread_calloc\n" +
3760 "#define public_fREe main_thread_free\n" +
3761 "#define public_cFREe main_thread_cfree\n" +
3762 "#define public_mALLOc main_thread_malloc\n" +
3763 "#define public_mEMALIGn main_thread_memalign\n" +
3764 "#define public_rEALLOc main_thread_realloc\n" +
3765 "#define public_vALLOc main_thread_valloc\n" +
3766 "#define public_pVALLOc main_thread_pvalloc\n" +
3767 "#define public_mALLINFo main_thread_mallinfo\n" +
3768 "#define public_mALLOPt main_thread_mallopt\n" +
3769 "#define public_mTRIm main_thread_malloc_trim\n" +
3770 "#define public_mSTATs main_thread_malloc_stats\n" +
3771 "#define public_mUSABLe main_thread_malloc_usable_size\n" +
3772 "#define public_iCALLOc main_thread_independent_calloc\n" +
3773 "#define public_iCOMALLOc main_thread_independent_comalloc\n" +
3774 "#else /* USE_DL_PREFIX */\n" +
3775 "#define public_cALLOc calloc\n" +
3776 "#define public_fREe free\n" +
3777 "#define public_cFREe cfree\n" +
3778 "#define public_mALLOc malloc\n" +
3779 "#define public_mEMALIGn memalign\n" +
3780 "#define public_rEALLOc realloc\n" +
3781 "#define public_vALLOc valloc\n" +
3782 "#define public_pVALLOc pvalloc\n" +
3783 "#define public_mALLINFo mallinfo\n" +
3784 "#define public_mALLOPt mallopt\n" +
3785 "#define public_mTRIm malloc_trim\n" +
3786 "#define public_mSTATs malloc_stats\n" +
3787 "#define public_mUSABLe malloc_usable_size\n" +
3788 "#define public_iCALLOc independent_calloc\n" +
3789 "#define public_iCOMALLOc independent_comalloc\n" +
3790 "#endif /* USE_DL_PREFIX */\n" +
3791 "\n" +
3792 "\n" +
3793 "/*\n" +
3794 " HAVE_MEMCPY should be defined if you are not otherwise using\n" +
3795 " ANSI STD C, but still have memcpy and memset in your C library\n" +
3796 " and want to use them in calloc and realloc. Otherwise simple\n" +
3797 " macro versions are defined below.\n" +
3798 "\n") +
3799 (" USE_MEMCPY should be defined as 1 if you actually want to\n" +
3800 " have memset and memcpy called. People report that the macro\n" +
3801 " versions are faster than libc versions on some systems.\n" +
3802 "\n" +
3803 " Even if USE_MEMCPY is set to 1, loops to copy/clear small chunks\n" +
3804 " (of <= 36 bytes) are manually unrolled in realloc and calloc.\n" +
3805 "*/\n" +
3806 "\n" +
3807 "#define HAVE_MEMCPY\n" +
3808 "\n" +
3809 "#ifndef USE_MEMCPY\n" +
3810 "#ifdef HAVE_MEMCPY\n" +
3811 "#define USE_MEMCPY 1\n" +
3812 "#else\n" +
3813 "#define USE_MEMCPY 0\n" +
3814 "#endif\n" +
3815 "#endif\n" +
3816 "\n" +
3817 "\n" +
3818 "#if (__STD_C || defined(HAVE_MEMCPY))\n" +
3819 "\n" +
3820 "#ifdef WIN32\n" +
3821 "/* On Win32 memset and memcpy are already declared in windows.h */\n" +
3822 "#else\n" +
3823 "#if __STD_C\n" +
3824 "extern \"C\" {\n" +
3825 "void* memset(void*, int, size_t);\n" +
3826 "void* memcpy(void*, const void*, size_t);\n" +
3827 "}\n" +
3828 "#else\n" +
3829 "extern \"C\" {\n" +
3830 "Void_t* memset();\n" +
3831 "Void_t* memcpy();\n" +
3832 "}\n" +
3833 "#endif\n" +
3834 "#endif\n" +
3835 "#endif\n" +
3836 "\n" +
3837 "/*\n" +
3838 " MALLOC_FAILURE_ACTION is the action to take before \"return 0\" when\n" +
3839 " malloc fails to be able to return memory, either because memory is\n" +
3840 " exhausted or because of illegal arguments.\n" +
3841 "\n" +
3842 " By default, sets errno if running on STD_C platform, else does nothing.\n" +
3843 "*/\n" +
3844 "\n" +
3845 "#ifndef MALLOC_FAILURE_ACTION\n" +
3846 "#if __STD_C\n" +
3847 "#define MALLOC_FAILURE_ACTION \\n" +
3848 " errno = ENOMEM;\n" +
3849 "\n" +
3850 "#else\n" +
3851 "#define MALLOC_FAILURE_ACTION\n" +
3852 "#endif\n" +
3853 "#endif\n" +
3854 "\n" +
3855 "/*\n" +
3856 " MORECORE-related declarations. By default, rely on sbrk\n" +
3857 "*/\n" +
3858 "\n" +
3859 "\n" +
3860 "#ifdef LACKS_UNISTD_H\n" +
3861 "#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)\n" +
3862 "#if __STD_C\n" +
3863 "extern Void_t* sbrk(ptrdiff_t);\n" +
3864 "#else\n" +
3865 "extern Void_t* sbrk();\n" +
3866 "#endif\n" +
3867 "#endif\n" +
3868 "#endif\n" +
3869 "\n" +
3870 "/*\n" +
3871 " MORECORE is the name of the routine to call to obtain more memory\n" +
3872 " from the system. See below for general guidance on writing\n" +
3873 " alternative MORECORE functions, as well as a version for WIN32 and a\n" +
3874 " sample version for pre-OSX macos.\n" +
3875 "*/\n" +
3876 "\n" +
3877 "#ifndef MORECORE\n" +
3878 "#define MORECORE sbrk\n" +
3879 "#endif\n" +
3880 "\n" +
3881 "/*\n" +
3882 " MORECORE_FAILURE is the value returned upon failure of MORECORE\n" +
3883 " as well as mmap. Since it cannot be an otherwise valid memory address,\n" +
3884 " and must reflect values of standard sys calls, you probably ought not\n" +
3885 " try to redefine it.\n" +
3886 "*/\n" +
3887 "\n" +
3888 "#ifndef MORECORE_FAILURE\n" +
3889 "#define MORECORE_FAILURE (-1)\n" +
3890 "#endif\n" +
3891 "\n" +
3892 "/*\n" +
3893 " If MORECORE_CONTIGUOUS is true, take advantage of fact that\n" +
3894 " consecutive calls to MORECORE with positive arguments always return\n" +
3895 " contiguous increasing addresses. This is true of unix sbrk. Even\n" +
3896 " if not defined, when regions happen to be contiguous, malloc will\n" +
3897 " permit allocations spanning regions obtained from different\n" +
3898 " calls. But defining this when applicable enables some stronger\n" +
3899 " consistency checks and space efficiencies.\n" +
3900 "*/\n" +
3901 "\n" +
3902 "#ifndef MORECORE_CONTIGUOUS\n" +
3903 "#define MORECORE_CONTIGUOUS 1\n" +
3904 "#endif\n" +
3905 "\n" +
3906 "/*\n" +
3907 " Define MORECORE_CANNOT_TRIM if your version of MORECORE\n" +
3908 " cannot release space back to the system when given negative\n" +
3909 " arguments. This is generally necessary only if you are using\n" +
3910 " a hand-crafted MORECORE function that cannot handle negative arguments.\n" +
3911 "*/\n" +
3912 "\n" +
3913 "/* #define MORECORE_CANNOT_TRIM */\n" +
3914 "\n" +
3915 "\n" +
3916 "/*\n" +
3917 " Define HAVE_MMAP as true to optionally make malloc() use mmap() to\n" +
3918 " allocate very large blocks. These will be returned to the\n" +
3919 " operating system immediately after a free(). Also, if mmap\n" +
3920 " is available, it is used as a backup strategy in cases where\n" +
3921 " MORECORE fails to provide space from system.\n" +
3922 "\n" +
3923 " This malloc is best tuned to work with mmap for large requests.\n" +
3924 " If you do not have mmap, operations involving very large chunks (1MB\n" +
3925 " or so) may be slower than you'd like.\n" +
3926 "*/\n" +
3927 "\n" +
3928 "#ifndef HAVE_MMAP\n" +
3929 "#define HAVE_MMAP 1\n" +
3930 "#endif\n" +
3931 "\n" +
3932 "#if HAVE_MMAP\n" +
3933 "/*\n" +
3934 " Standard unix mmap using /dev/zero clears memory so calloc doesn't\n" +
3935 " need to.\n" +
3936 "*/\n" +
3937 "\n" +
3938 "#ifndef MMAP_CLEARS\n" +
3939 "#define MMAP_CLEARS 1\n" +
3940 "#endif\n" +
3941 "\n" +
3942 "#else /* no mmap */\n" +
3943 "#ifndef MMAP_CLEARS\n" +
3944 "#define MMAP_CLEARS 0\n" +
3945 "#endif\n" +
3946 "#endif\n" +
3947 "\n" +
3948 "\n" +
3949 "/*\n") +
3950 (" MMAP_AS_MORECORE_SIZE is the minimum mmap size argument to use if\n" +
3951 " sbrk fails, and mmap is used as a backup (which is done only if\n" +
3952 " HAVE_MMAP). The value must be a multiple of page size. This\n" +
3953 " backup strategy generally applies only when systems have \"holes\" in\n" +
3954 " address space, so sbrk cannot perform contiguous expansion, but\n" +
3955 " there is still space available on system. On systems for which\n" +
3956 " this is known to be useful (i.e. most linux kernels), this occurs\n" +
3957 " only when programs allocate huge amounts of memory. Between this,\n" +
3958 " and the fact that mmap regions tend to be limited, the size should\n" +
3959 " be large, to avoid too many mmap calls and thus avoid running out\n" +
3960 " of kernel resources.\n" +
3961 "*/\n" +
3962 "\n" +
3963 "#ifndef MMAP_AS_MORECORE_SIZE\n" +
3964 "#define MMAP_AS_MORECORE_SIZE (1024 * 1024)\n" +
3965 "#endif\n" +
3966 "\n" +
3967 "/*\n" +
3968 " Define HAVE_MREMAP to make realloc() use mremap() to re-allocate\n" +
3969 " large blocks. This is currently only possible on Linux with\n" +
3970 " kernel versions newer than 1.3.77.\n" +
3971 "*/\n" +
3972 "\n" +
3973 "#ifndef HAVE_MREMAP\n" +
3974 "#ifdef linux\n" +
3975 "#define HAVE_MREMAP 1\n" +
3976 "#else\n" +
3977 "#define HAVE_MREMAP 0\n" +
3978 "#endif\n" +
3979 "\n" +
3980 "#endif /* HAVE_MMAP */\n" +
3981 "\n" +
3982 "\n" +
3983 "/*\n" +
3984 " The system page size. To the extent possible, this malloc manages\n" +
3985 " memory from the system in page-size units. Note that this value is\n" +
3986 " cached during initialization into a field of malloc_state. So even\n" +
3987 " if malloc_getpagesize is a function, it is only called once.\n" +
3988 "\n" +
3989 " The following mechanics for getpagesize were adapted from bsd/gnu\n" +
3990 " getpagesize.h. If none of the system-probes here apply, a value of\n" +
3991 " 4096 is used, which should be OK: If they don't apply, then using\n" +
3992 " the actual value probably doesn't impact performance.\n" +
3993 "*/\n" +
3994 "\n" +
3995 "\n" +
3996 "#ifndef malloc_getpagesize\n" +
3997 "\n" +
3998 "#ifndef LACKS_UNISTD_H\n" +
3999 "# include <unistd.h>\n" +
4000 "#endif\n" +
4001 "\n" +
4002 "# ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */\n" +
4003 "# ifndef _SC_PAGE_SIZE\n" +
4004 "# define _SC_PAGE_SIZE _SC_PAGESIZE\n" +
4005 "# endif\n" +
4006 "# endif\n" +
4007 "\n" +
4008 "# ifdef _SC_PAGE_SIZE\n" +
4009 "# define malloc_getpagesize sysconf(_SC_PAGE_SIZE)\n" +
4010 "# else\n" +
4011 "# if defined(BSD) || defined(DGUX) || defined(HAVE_GETPAGESIZE)\n" +
4012 " extern size_t getpagesize();\n" +
4013 "# define malloc_getpagesize getpagesize()\n" +
4014 "# else\n" +
4015 "# ifdef WIN32 /* use supplied emulation of getpagesize */\n" +
4016 "# define malloc_getpagesize getpagesize()\n" +
4017 "# else\n" +
4018 "# ifndef LACKS_SYS_PARAM_H\n" +
4019 "# include <sys/param.h>\n" +
4020 "# endif\n" +
4021 "# ifdef EXEC_PAGESIZE\n" +
4022 "# define malloc_getpagesize EXEC_PAGESIZE\n" +
4023 "# else\n" +
4024 "# ifdef NBPG\n" +
4025 "# ifndef CLSIZE\n" +
4026 "# define malloc_getpagesize NBPG\n" +
4027 "# else\n" +
4028 "# define malloc_getpagesize (NBPG * CLSIZE)\n" +
4029 "# endif\n" +
4030 "# else\n" +
4031 "# ifdef NBPC\n" +
4032 "# define malloc_getpagesize NBPC\n" +
4033 "# else\n" +
4034 "# ifdef PAGESIZE\n" +
4035 "# define malloc_getpagesize PAGESIZE\n" +
4036 "# else /* just guess */\n" +
4037 "# define malloc_getpagesize (4096)\n" +
4038 "# endif\n" +
4039 "# endif\n" +
4040 "# endif\n" +
4041 "# endif\n" +
4042 "# endif\n" +
4043 "# endif\n" +
4044 "# endif\n" +
4045 "#endif\n" +
4046 "\n" +
4047 "/*\n" +
4048 " This version of malloc supports the standard SVID/XPG mallinfo\n" +
4049 " routine that returns a struct containing usage properties and\n" +
4050 " statistics. It should work on any SVID/XPG compliant system that has\n" +
4051 " a /usr/include/malloc.h defining struct mallinfo. (If you'd like to\n" +
4052 " install such a thing yourself, cut out the preliminary declarations\n" +
4053 " as described above and below and save them in a malloc.h file. But\n" +
4054 " there's no compelling reason to bother to do this.)\n" +
4055 "\n" +
4056 " The main declaration needed is the mallinfo struct that is returned\n" +
4057 " (by-copy) by mallinfo(). The SVID/XPG malloinfo struct contains a\n" +
4058 " bunch of fields that are not even meaningful in this version of\n" +
4059 " malloc. These fields are are instead filled by mallinfo() with\n" +
4060 " other numbers that might be of interest.\n" +
4061 "\n" +
4062 " HAVE_USR_INCLUDE_MALLOC_H should be set if you have a\n" +
4063 " /usr/include/malloc.h file that includes a declaration of struct\n" +
4064 " mallinfo. If so, it is included; else an SVID2/XPG2 compliant\n" +
4065 " version is declared below. These must be precisely the same for\n" +
4066 " mallinfo() to work. The original SVID version of this struct,\n" +
4067 " defined on most systems with mallinfo, declares all fields as\n" +
4068 " ints. But some others define as unsigned long. If your system\n" +
4069 " defines the fields using a type of different width than listed here,\n" +
4070 " you must #include your system version and #define\n" +
4071 " HAVE_USR_INCLUDE_MALLOC_H.\n" +
4072 "*/\n" +
4073 "\n" +
4074 "/* #define HAVE_USR_INCLUDE_MALLOC_H */\n" +
4075 "\n" +
4076 "#ifdef HAVE_USR_INCLUDE_MALLOC_H\n" +
4077 "#include \"/usr/include/malloc.h\"\n" +
4078 "#else\n" +
4079 "\n" +
4080 "/* SVID2/XPG mallinfo structure */\n" +
4081 "\n" +
4082 "struct mallinfo {\n" +
4083 " int arena; /* non-mmapped space allocated from system */\n" +
4084 " int ordblks; /* number of free chunks */\n" +
4085 " int smblks; /* number of fastbin blocks */\n" +
4086 " int hblks; /* number of mmapped regions */\n" +
4087 " int hblkhd; /* space in mmapped regions */\n" +
4088 " int usmblks; /* maximum total allocated space */\n" +
4089 " int fsmblks; /* space available in freed fastbin blocks */\n" +
4090 " int uordblks; /* total allocated space */\n" +
4091 " int fordblks; /* total free space */\n" +
4092 " int keepcost; /* top-most, releasable (via malloc_trim) space */\n" +
4093 "};\n" +
4094 "\n" +
4095 "/*\n" +
4096 " SVID/XPG defines four standard parameter numbers for mallopt,\n" +
4097 " normally defined in malloc.h. Only one of these (M_MXFAST) is used\n" +
4098 " in this malloc. The others (M_NLBLKS, M_GRAIN, M_KEEP) don't apply,\n" +
4099 " so setting them has no effect. But this malloc also supports other\n" +
4100 " options in mallopt described below.\n" +
4101 "*/\n") +
4102 ("#endif\n" +
4103 "\n" +
4104 "\n" +
4105 "/* ---------- description of public routines ------------ */\n" +
4106 "\n" +
4107 "/*\n" +
4108 " malloc(size_t n)\n" +
4109 " Returns a pointer to a newly allocated chunk of at least n bytes, or null\n" +
4110 " if no space is available. Additionally, on failure, errno is\n" +
4111 " set to ENOMEM on ANSI C systems.\n" +
4112 "\n" +
4113 " If n is zero, malloc returns a minumum-sized chunk. (The minimum\n" +
4114 " size is 16 bytes on most 32bit systems, and 24 or 32 bytes on 64bit\n" +
4115 " systems.) On most systems, size_t is an unsigned type, so calls\n" +
4116 " with negative arguments are interpreted as requests for huge amounts\n" +
4117 " of space, which will often fail. The maximum supported value of n\n" +
4118 " differs across systems, but is in all cases less than the maximum\n" +
4119 " representable value of a size_t.\n" +
4120 "*/\n" +
4121 "#if __STD_C\n" +
4122 "Void_t* public_mALLOc(size_t);\n" +
4123 "#else\n" +
4124 "Void_t* public_mALLOc();\n" +
4125 "#endif\n" +
4126 "\n" +
4127 "/*\n" +
4128 " free(Void_t* p)\n" +
4129 " Releases the chunk of memory pointed to by p, that had been previously\n" +
4130 " allocated using malloc or a related routine such as realloc.\n" +
4131 " It has no effect if p is null. It can have arbitrary (i.e., bad!)\n" +
4132 " effects if p has already been freed.\n" +
4133 "\n" +
4134 " Unless disabled (using mallopt), freeing very large spaces will\n" +
4135 " when possible, automatically trigger operations that give\n" +
4136 " back unused memory to the system, thus reducing program footprint.\n" +
4137 "*/\n" +
4138 "#if __STD_C\n" +
4139 "void public_fREe(Void_t*);\n" +
4140 "#else\n" +
4141 "void public_fREe();\n" +
4142 "#endif\n" +
4143 "\n" +
4144 "/*\n" +
4145 " calloc(size_t n_elements, size_t element_size);\n" +
4146 " Returns a pointer to n_elements * element_size bytes, with all locations\n" +
4147 " set to zero.\n" +
4148 "*/\n" +
4149 "#if __STD_C\n" +
4150 "Void_t* public_cALLOc(size_t, size_t);\n" +
4151 "#else\n" +
4152 "Void_t* public_cALLOc();\n" +
4153 "#endif\n" +
4154 "\n" +
4155 "/*\n" +
4156 " realloc(Void_t* p, size_t n)\n" +
4157 " Returns a pointer to a chunk of size n that contains the same data\n" +
4158 " as does chunk p up to the minimum of (n, p's size) bytes, or null\n" +
4159 " if no space is available.\n" +
4160 "\n" +
4161 " The returned pointer may or may not be the same as p. The algorithm\n" +
4162 " prefers extending p when possible, otherwise it employs the\n" +
4163 " equivalent of a malloc-copy-free sequence.\n" +
4164 "\n" +
4165 " If p is null, realloc is equivalent to malloc.\n" +
4166 "\n" +
4167 " If space is not available, realloc returns null, errno is set (if on\n" +
4168 " ANSI) and p is NOT freed.\n" +
4169 "\n" +
4170 " if n is for fewer bytes than already held by p, the newly unused\n" +
4171 " space is lopped off and freed if possible. Unless the #define\n" +
4172 " REALLOC_ZERO_BYTES_FREES is set, realloc with a size argument of\n" +
4173 " zero (re)allocates a minimum-sized chunk.\n" +
4174 "\n" +
4175 " Large chunks that were internally obtained via mmap will always\n" +
4176 " be reallocated using malloc-copy-free sequences unless\n" +
4177 " the system supports MREMAP (currently only linux).\n" +
4178 "\n" +
4179 " The old unix realloc convention of allowing the last-free'd chunk\n" +
4180 " to be used as an argument to realloc is not supported.\n" +
4181 "*/\n" +
4182 "#if __STD_C\n" +
4183 "Void_t* public_rEALLOc(Void_t*, size_t);\n" +
4184 "#else\n" +
4185 "Void_t* public_rEALLOc();\n" +
4186 "#endif\n" +
4187 "\n" +
4188 "/*\n" +
4189 " memalign(size_t alignment, size_t n);\n" +
4190 " Returns a pointer to a newly allocated chunk of n bytes, aligned\n" +
4191 " in accord with the alignment argument.\n" +
4192 "\n" +
4193 " The alignment argument should be a power of two. If the argument is\n" +
4194 " not a power of two, the nearest greater power is used.\n" +
4195 " 8-byte alignment is guaranteed by normal malloc calls, so don't\n" +
4196 " bother calling memalign with an argument of 8 or less.\n" +
4197 "\n" +
4198 " Overreliance on memalign is a sure way to fragment space.\n" +
4199 "*/\n" +
4200 "#if __STD_C\n" +
4201 "Void_t* public_mEMALIGn(size_t, size_t);\n" +
4202 "#else\n" +
4203 "Void_t* public_mEMALIGn();\n" +
4204 "#endif\n" +
4205 "\n" +
4206 "/*\n" +
4207 " valloc(size_t n);\n" +
4208 " Equivalent to memalign(pagesize, n), where pagesize is the page\n" +
4209 " size of the system. If the pagesize is unknown, 4096 is used.\n" +
4210 "*/\n" +
4211 "#if __STD_C\n" +
4212 "Void_t* public_vALLOc(size_t);\n" +
4213 "#else\n" +
4214 "Void_t* public_vALLOc();\n" +
4215 "#endif\n" +
4216 "\n" +
4217 "\n" +
4218 "\n" +
4219 "/*\n" +
4220 " mallopt(int parameter_number, int parameter_value)\n" +
4221 " Sets tunable parameters The format is to provide a\n" +
4222 " (parameter-number, parameter-value) pair. mallopt then sets the\n" +
4223 " corresponding parameter to the argument value if it can (i.e., so\n" +
4224 " long as the value is meaningful), and returns 1 if successful else\n" +
4225 " 0. SVID/XPG/ANSI defines four standard param numbers for mallopt,\n" +
4226 " normally defined in malloc.h. Only one of these (M_MXFAST) is used\n" +
4227 " in this malloc. The others (M_NLBLKS, M_GRAIN, M_KEEP) don't apply,\n" +
4228 " so setting them has no effect. But this malloc also supports four\n" +
4229 " other options in mallopt. See below for details. Briefly, supported\n" +
4230 " parameters are as follows (listed defaults are for \"typical\"\n" +
4231 " configurations).\n" +
4232 "\n" +
4233 " Symbol param # default allowed param values\n" +
4234 " M_MXFAST 1 64 0-80 (0 disables fastbins)\n" +
4235 " M_TRIM_THRESHOLD -1 256*1024 any (-1U disables trimming)\n" +
4236 " M_TOP_PAD -2 0 any\n" +
4237 " M_MMAP_THRESHOLD -3 256*1024 any (or 0 if no MMAP support)\n" +
4238 " M_MMAP_MAX -4 65536 any (0 disables use of mmap)\n" +
4239 "*/\n" +
4240 "#if __STD_C\n" +
4241 "int public_mALLOPt(int, int);\n" +
4242 "#else\n" +
4243 "int public_mALLOPt();\n" +
4244 "#endif\n" +
4245 "\n" +
4246 "\n" +
4247 "/*\n" +
4248 " mallinfo()\n" +
4249 " Returns (by copy) a struct containing various summary statistics:\n" +
4250 "\n") +
4251 (" arena: current total non-mmapped bytes allocated from system\n" +
4252 " ordblks: the number of free chunks\n" +
4253 " smblks: the number of fastbin blocks (i.e., small chunks that\n" +
4254 " have been freed but not use resused or consolidated)\n" +
4255 " hblks: current number of mmapped regions\n" +
4256 " hblkhd: total bytes held in mmapped regions\n" +
4257 " usmblks: the maximum total allocated space. This will be greater\n" +
4258 " than current total if trimming has occurred.\n" +
4259 " fsmblks: total bytes held in fastbin blocks\n" +
4260 " uordblks: current total allocated space (normal or mmapped)\n" +
4261 " fordblks: total free space\n" +
4262 " keepcost: the maximum number of bytes that could ideally be released\n" +
4263 " back to system via malloc_trim. (\"ideally\" means that\n" +
4264 " it ignores page restrictions etc.)\n" +
4265 "\n" +
4266 " Because these fields are ints, but internal bookkeeping may\n" +
4267 " be kept as longs, the reported values may wrap around zero and\n" +
4268 " thus be inaccurate.\n" +
4269 "*/\n" +
4270 "#if __STD_C\n" +
4271 "struct mallinfo public_mALLINFo(void);\n" +
4272 "#else\n" +
4273 "struct mallinfo public_mALLINFo();\n" +
4274 "#endif\n" +
4275 "\n" +
4276 "/*\n" +
4277 " independent_calloc(size_t n_elements, size_t element_size, Void_t* chunks[]);\n" +
4278 "\n" +
4279 " independent_calloc is similar to calloc, but instead of returning a\n" +
4280 " single cleared space, it returns an array of pointers to n_elements\n" +
4281 " independent elements that can hold contents of size elem_size, each\n" +
4282 " of which starts out cleared, and can be independently freed,\n" +
4283 " realloc'ed etc. The elements are guaranteed to be adjacently\n" +
4284 " allocated (this is not guaranteed to occur with multiple callocs or\n" +
4285 " mallocs), which may also improve cache locality in some\n" +
4286 " applications.\n" +
4287 "\n" +
4288 " The \"chunks\" argument is optional (i.e., may be null, which is\n" +
4289 " probably the most typical usage). If it is null, the returned array\n" +
4290 " is itself dynamically allocated and should also be freed when it is\n" +
4291 " no longer needed. Otherwise, the chunks array must be of at least\n" +
4292 " n_elements in length. It is filled in with the pointers to the\n" +
4293 " chunks.\n" +
4294 "\n" +
4295 " In either case, independent_calloc returns this pointer array, or\n" +
4296 " null if the allocation failed. If n_elements is zero and \"chunks\"\n" +
4297 " is null, it returns a chunk representing an array with zero elements\n" +
4298 " (which should be freed if not wanted).\n" +
4299 "\n" +
4300 " Each element must be individually freed when it is no longer\n" +
4301 " needed. If you'd like to instead be able to free all at once, you\n" +
4302 " should instead use regular calloc and assign pointers into this\n" +
4303 " space to represent elements. (In this case though, you cannot\n" +
4304 " independently free elements.)\n" +
4305 "\n" +
4306 " independent_calloc simplifies and speeds up implementations of many\n" +
4307 " kinds of pools. It may also be useful when constructing large data\n" +
4308 " structures that initially have a fixed number of fixed-sized nodes,\n" +
4309 " but the number is not known at compile time, and some of the nodes\n" +
4310 " may later need to be freed. For example:\n" +
4311 "\n" +
4312 " struct Node { int item; struct Node* next; };\n" +
4313 "\n" +
4314 " struct Node* build_list() {\n" +
4315 " struct Node** pool;\n" +
4316 " int n = read_number_of_nodes_needed();\n" +
4317 " if (n <= 0) return 0;\n" +
4318 " pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0);\n" +
4319 " if (pool == 0) die();\n" +
4320 " // organize into a linked list...\n" +
4321 " struct Node* first = pool[0];\n" +
4322 " for (i = 0; i < n-1; ++i)\n" +
4323 " pool[i]->next = pool[i+1];\n" +
4324 " free(pool); // Can now free the array (or not, if it is needed later)\n" +
4325 " return first;\n" +
4326 " }\n" +
4327 "*/\n" +
4328 "#if __STD_C\n" +
4329 "Void_t** public_iCALLOc(size_t, size_t, Void_t**);\n" +
4330 "#else\n" +
4331 "Void_t** public_iCALLOc();\n" +
4332 "#endif\n" +
4333 "\n" +
4334 "/*\n" +
4335 " independent_comalloc(size_t n_elements, size_t sizes[], Void_t* chunks[]);\n" +
4336 "\n" +
4337 " independent_comalloc allocates, all at once, a set of n_elements\n" +
4338 " chunks with sizes indicated in the \"sizes\" array. It returns\n" +
4339 " an array of pointers to these elements, each of which can be\n" +
4340 " independently freed, realloc'ed etc. The elements are guaranteed to\n" +
4341 " be adjacently allocated (this is not guaranteed to occur with\n" +
4342 " multiple callocs or mallocs), which may also improve cache locality\n" +
4343 " in some applications.\n" +
4344 "\n" +
4345 " The \"chunks\" argument is optional (i.e., may be null). If it is null\n" +
4346 " the returned array is itself dynamically allocated and should also\n" +
4347 " be freed when it is no longer needed. Otherwise, the chunks array\n" +
4348 " must be of at least n_elements in length. It is filled in with the\n" +
4349 " pointers to the chunks.\n" +
4350 "\n" +
4351 " In either case, independent_comalloc returns this pointer array, or\n" +
4352 " null if the allocation failed. If n_elements is zero and chunks is\n" +
4353 " null, it returns a chunk representing an array with zero elements\n" +
4354 " (which should be freed if not wanted).\n" +
4355 "\n" +
4356 " Each element must be individually freed when it is no longer\n" +
4357 " needed. If you'd like to instead be able to free all at once, you\n" +
4358 " should instead use a single regular malloc, and assign pointers at\n" +
4359 " particular offsets in the aggregate space. (In this case though, you\n" +
4360 " cannot independently free elements.)\n" +
4361 "\n" +
4362 " independent_comallac differs from independent_calloc in that each\n" +
4363 " element may have a different size, and also that it does not\n" +
4364 " automatically clear elements.\n" +
4365 "\n" +
4366 " independent_comalloc can be used to speed up allocation in cases\n" +
4367 " where several structs or objects must always be allocated at the\n" +
4368 " same time. For example:\n" +
4369 "\n" +
4370 " struct Head { ... }\n" +
4371 " struct Foot { ... }\n" +
4372 "\n" +
4373 " void send_message(char* msg) {\n" +
4374 " int msglen = strlen(msg);\n" +
4375 " size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) };\n" +
4376 " void* chunks[3];\n" +
4377 " if (independent_comalloc(3, sizes, chunks) == 0)\n" +
4378 " die();\n" +
4379 " struct Head* head = (struct Head*)(chunks[0]);\n" +
4380 " char* body = (char*)(chunks[1]);\n" +
4381 " struct Foot* foot = (struct Foot*)(chunks[2]);\n" +
4382 " // ...\n" +
4383 " }\n" +
4384 "\n" +
4385 " In general though, independent_comalloc is worth using only for\n" +
4386 " larger values of n_elements. For small values, you probably won't\n" +
4387 " detect enough difference from series of malloc calls to bother.\n" +
4388 "\n" +
4389 " Overuse of independent_comalloc can increase overall memory usage,\n" +
4390 " since it cannot reuse existing noncontiguous small chunks that\n" +
4391 " might be available for some of the elements.\n" +
4392 "*/\n" +
4393 "#if __STD_C\n" +
4394 "Void_t** public_iCOMALLOc(size_t, size_t*, Void_t**);\n" +
4395 "#else\n" +
4396 "Void_t** public_iCOMALLOc();\n" +
4397 "#endif\n" +
4398 "\n" +
4399 "\n" +
4400 "/*\n") +
4401 (" pvalloc(size_t n);\n" +
4402 " Equivalent to valloc(minimum-page-that-holds(n)), that is,\n" +
4403 " round up n to nearest pagesize.\n" +
4404 " */\n" +
4405 "#if __STD_C\n" +
4406 "Void_t* public_pVALLOc(size_t);\n" +
4407 "#else\n" +
4408 "Void_t* public_pVALLOc();\n" +
4409 "#endif\n" +
4410 "\n" +
4411 "/*\n" +
4412 " cfree(Void_t* p);\n" +
4413 " Equivalent to free(p).\n" +
4414 "\n" +
4415 " cfree is needed/defined on some systems that pair it with calloc,\n" +
4416 " for odd historical reasons (such as: cfree is used in example\n" +
4417 " code in the first edition of K&R).\n" +
4418 "*/\n" +
4419 "#if __STD_C\n" +
4420 "void public_cFREe(Void_t*);\n" +
4421 "#else\n" +
4422 "void public_cFREe();\n" +
4423 "#endif\n" +
4424 "\n" +
4425 "/*\n" +
4426 " malloc_trim(size_t pad);\n" +
4427 "\n" +
4428 " If possible, gives memory back to the system (via negative\n" +
4429 " arguments to sbrk) if there is unused memory at the `high' end of\n" +
4430 " the malloc pool. You can call this after freeing large blocks of\n" +
4431 " memory to potentially reduce the system-level memory requirements\n" +
4432 " of a program. However, it cannot guarantee to reduce memory. Under\n" +
4433 " some allocation patterns, some large free blocks of memory will be\n" +
4434 " locked between two used chunks, so they cannot be given back to\n" +
4435 " the system.\n" +
4436 "\n" +
4437 " The `pad' argument to malloc_trim represents the amount of free\n" +
4438 " trailing space to leave untrimmed. If this argument is zero,\n" +
4439 " only the minimum amount of memory to maintain internal data\n" +
4440 " structures will be left (one page or less). Non-zero arguments\n" +
4441 " can be supplied to maintain enough trailing space to service\n" +
4442 " future expected allocations without having to re-obtain memory\n" +
4443 " from the system.\n" +
4444 "\n" +
4445 " Malloc_trim returns 1 if it actually released any memory, else 0.\n" +
4446 " On systems that do not support \"negative sbrks\", it will always\n" +
4447 " rreturn 0.\n" +
4448 "*/\n" +
4449 "#if __STD_C\n" +
4450 "int public_mTRIm(size_t);\n" +
4451 "#else\n" +
4452 "int public_mTRIm();\n" +
4453 "#endif\n" +
4454 "\n" +
4455 "/*\n" +
4456 " malloc_usable_size(Void_t* p);\n" +
4457 "\n" +
4458 " Returns the number of bytes you can actually use in\n" +
4459 " an allocated chunk, which may be more than you requested (although\n" +
4460 " often not) due to alignment and minimum size constraints.\n" +
4461 " You can use this many bytes without worrying about\n" +
4462 " overwriting other allocated objects. This is not a particularly great\n" +
4463 " programming practice. malloc_usable_size can be more useful in\n" +
4464 " debugging and assertions, for example:\n" +
4465 "\n" +
4466 " p = malloc(n);\n" +
4467 " assert(malloc_usable_size(p) >= 256);\n" +
4468 "\n" +
4469 "*/\n" +
4470 "#if __STD_C\n" +
4471 "size_t public_mUSABLe(Void_t*);\n" +
4472 "#else\n" +
4473 "size_t public_mUSABLe();\n" +
4474 "#endif\n" +
4475 "\n" +
4476 "/*\n" +
4477 " malloc_stats();\n" +
4478 " Prints on stderr the amount of space obtained from the system (both\n" +
4479 " via sbrk and mmap), the maximum amount (which may be more than\n" +
4480 " current if malloc_trim and/or munmap got called), and the current\n" +
4481 " number of bytes allocated via malloc (or realloc, etc) but not yet\n" +
4482 " freed. Note that this is the number of bytes allocated, not the\n" +
4483 " number requested. It will be larger than the number requested\n" +
4484 " because of alignment and bookkeeping overhead. Because it includes\n" +
4485 " alignment wastage as being in use, this figure may be greater than\n" +
4486 " zero even when no user-level chunks are allocated.\n" +
4487 "\n" +
4488 " The reported current and maximum system memory can be inaccurate if\n" +
4489 " a program makes other calls to system memory allocation functions\n" +
4490 " (normally sbrk) outside of malloc.\n" +
4491 "\n" +
4492 " malloc_stats prints only the most commonly interesting statistics.\n" +
4493 " More information can be obtained by calling mallinfo.\n" +
4494 "\n" +
4495 "*/\n" +
4496 "#if __STD_C\n" +
4497 "void public_mSTATs();\n" +
4498 "#else\n" +
4499 "void public_mSTATs();\n" +
4500 "#endif\n" +
4501 "\n" +
4502 "/* mallopt tuning options */\n" +
4503 "\n" +
4504 "/*\n" +
4505 " M_MXFAST is the maximum request size used for \"fastbins\", special bins\n" +
4506 " that hold returned chunks without consolidating their spaces. This\n" +
4507 " enables future requests for chunks of the same size to be handled\n" +
4508 " very quickly, but can increase fragmentation, and thus increase the\n" +
4509 " overall memory footprint of a program.\n" +
4510 "\n" +
4511 " This malloc manages fastbins very conservatively yet still\n" +
4512 " efficiently, so fragmentation is rarely a problem for values less\n" +
4513 " than or equal to the default. The maximum supported value of MXFAST\n" +
4514 " is 80. You wouldn't want it any higher than this anyway. Fastbins\n" +
4515 " are designed especially for use with many small structs, objects or\n" +
4516 " strings -- the default handles structs/objects/arrays with sizes up\n" +
4517 " to 16 4byte fields, or small strings representing words, tokens,\n" +
4518 " etc. Using fastbins for larger objects normally worsens\n" +
4519 " fragmentation without improving speed.\n" +
4520 "\n" +
4521 " M_MXFAST is set in REQUEST size units. It is internally used in\n" +
4522 " chunksize units, which adds padding and alignment. You can reduce\n" +
4523 " M_MXFAST to 0 to disable all use of fastbins. This causes the malloc\n" +
4524 " algorithm to be a closer approximation of fifo-best-fit in all cases,\n" +
4525 " not just for larger requests, but will generally cause it to be\n" +
4526 " slower.\n" +
4527 "*/\n" +
4528 "\n" +
4529 "\n" +
4530 "/* M_MXFAST is a standard SVID/XPG tuning option, usually listed in malloc.h */\n" +
4531 "#ifndef M_MXFAST\n" +
4532 "#define M_MXFAST 1\n" +
4533 "#endif\n" +
4534 "\n" +
4535 "#ifndef DEFAULT_MXFAST\n" +
4536 "#define DEFAULT_MXFAST 64\n" +
4537 "#endif\n" +
4538 "\n" +
4539 "\n" +
4540 "/*\n" +
4541 " M_TRIM_THRESHOLD is the maximum amount of unused top-most memory\n" +
4542 " to keep before releasing via malloc_trim in free().\n" +
4543 "\n" +
4544 " Automatic trimming is mainly useful in long-lived programs.\n" +
4545 " Because trimming via sbrk can be slow on some systems, and can\n" +
4546 " sometimes be wasteful (in cases where programs immediately\n" +
4547 " afterward allocate more large chunks) the value should be high\n" +
4548 " enough so that your overall system performance would improve by\n" +
4549 " releasing this much memory.\n" +
4550 "\n") +
4551 (" The trim threshold and the mmap control parameters (see below)\n" +
4552 " can be traded off with one another. Trimming and mmapping are\n" +
4553 " two different ways of releasing unused memory back to the\n" +
4554 " system. Between these two, it is often possible to keep\n" +
4555 " system-level demands of a long-lived program down to a bare\n" +
4556 " minimum. For example, in one test suite of sessions measuring\n" +
4557 " the XF86 X server on Linux, using a trim threshold of 128K and a\n" +
4558 " mmap threshold of 192K led to near-minimal long term resource\n" +
4559 " consumption.\n" +
4560 "\n" +
4561 " If you are using this malloc in a long-lived program, it should\n" +
4562 " pay to experiment with these values. As a rough guide, you\n" +
4563 " might set to a value close to the average size of a process\n" +
4564 " (program) running on your system. Releasing this much memory\n" +
4565 " would allow such a process to run in memory. Generally, it's\n" +
4566 " worth it to tune for trimming rather tham memory mapping when a\n" +
4567 " program undergoes phases where several large chunks are\n" +
4568 " allocated and released in ways that can reuse each other's\n" +
4569 " storage, perhaps mixed with phases where there are no such\n" +
4570 " chunks at all. And in well-behaved long-lived programs,\n" +
4571 " controlling release of large blocks via trimming versus mapping\n" +
4572 " is usually faster.\n" +
4573 "\n" +
4574 " However, in most programs, these parameters serve mainly as\n" +
4575 " protection against the system-level effects of carrying around\n" +
4576 " massive amounts of unneeded memory. Since frequent calls to\n" +
4577 " sbrk, mmap, and munmap otherwise degrade performance, the default\n" +
4578 " parameters are set to relatively high values that serve only as\n" +
4579 " safeguards.\n" +
4580 "\n" +
4581 " The trim value must be greater than page size to have any useful\n" +
4582 " effect. To disable trimming completely, you can set to\n" +
4583 " (unsigned long)(-1)\n" +
4584 "\n" +
4585 " Trim settings interact with fastbin (MXFAST) settings: Unless\n" +
4586 " TRIM_FASTBINS is defined, automatic trimming never takes place upon\n" +
4587 " freeing a chunk with size less than or equal to MXFAST. Trimming is\n" +
4588 " instead delayed until subsequent freeing of larger chunks. However,\n" +
4589 " you can still force an attempted trim by calling malloc_trim.\n" +
4590 "\n" +
4591 " Also, trimming is not generally possible in cases where\n" +
4592 " the main arena is obtained via mmap.\n" +
4593 "\n" +
4594 " Note that the trick some people use of mallocing a huge space and\n" +
4595 " then freeing it at program startup, in an attempt to reserve system\n" +
4596 " memory, doesn't have the intended effect under automatic trimming,\n" +
4597 " since that memory will immediately be returned to the system.\n" +
4598 "*/\n" +
4599 "\n" +
4600 "#define M_TRIM_THRESHOLD -1\n" +
4601 "\n" +
4602 "#ifndef DEFAULT_TRIM_THRESHOLD\n" +
4603 "#define DEFAULT_TRIM_THRESHOLD (256 * 1024)\n" +
4604 "#endif\n" +
4605 "\n" +
4606 "/*\n" +
4607 " M_TOP_PAD is the amount of extra `padding' space to allocate or\n" +
4608 " retain whenever sbrk is called. It is used in two ways internally:\n" +
4609 "\n" +
4610 " * When sbrk is called to extend the top of the arena to satisfy\n" +
4611 " a new malloc request, this much padding is added to the sbrk\n" +
4612 " request.\n" +
4613 "\n" +
4614 " * When malloc_trim is called automatically from free(),\n" +
4615 " it is used as the `pad' argument.\n" +
4616 "\n" +
4617 " In both cases, the actual amount of padding is rounded\n" +
4618 " so that the end of the arena is always a system page boundary.\n" +
4619 "\n" +
4620 " The main reason for using padding is to avoid calling sbrk so\n" +
4621 " often. Having even a small pad greatly reduces the likelihood\n" +
4622 " that nearly every malloc request during program start-up (or\n" +
4623 " after trimming) will invoke sbrk, which needlessly wastes\n" +
4624 " time.\n" +
4625 "\n" +
4626 " Automatic rounding-up to page-size units is normally sufficient\n" +
4627 " to avoid measurable overhead, so the default is 0. However, in\n" +
4628 " systems where sbrk is relatively slow, it can pay to increase\n" +
4629 " this value, at the expense of carrying around more memory than\n" +
4630 " the program needs.\n" +
4631 "*/\n" +
4632 "\n" +
4633 "#define M_TOP_PAD -2\n" +
4634 "\n" +
4635 "#ifndef DEFAULT_TOP_PAD\n" +
4636 "#define DEFAULT_TOP_PAD (0)\n" +
4637 "#endif\n" +
4638 "\n" +
4639 "/*\n" +
4640 " M_MMAP_THRESHOLD is the request size threshold for using mmap()\n" +
4641 " to service a request. Requests of at least this size that cannot\n" +
4642 " be allocated using already-existing space will be serviced via mmap.\n" +
4643 " (If enough normal freed space already exists it is used instead.)\n" +
4644 "\n" +
4645 " Using mmap segregates relatively large chunks of memory so that\n" +
4646 " they can be individually obtained and released from the host\n" +
4647 " system. A request serviced through mmap is never reused by any\n" +
4648 " other request (at least not directly; the system may just so\n" +
4649 " happen to remap successive requests to the same locations).\n" +
4650 "\n" +
4651 " Segregating space in this way has the benefits that:\n" +
4652 "\n" +
4653 " 1. Mmapped space can ALWAYS be individually released back\n" +
4654 " to the system, which helps keep the system level memory\n" +
4655 " demands of a long-lived program low.\n" +
4656 " 2. Mapped memory can never become `locked' between\n" +
4657 " other chunks, as can happen with normally allocated chunks, which\n" +
4658 " means that even trimming via malloc_trim would not release them.\n" +
4659 " 3. On some systems with \"holes\" in address spaces, mmap can obtain\n" +
4660 " memory that sbrk cannot.\n" +
4661 "\n" +
4662 " However, it has the disadvantages that:\n" +
4663 "\n" +
4664 " 1. The space cannot be reclaimed, consolidated, and then\n" +
4665 " used to service later requests, as happens with normal chunks.\n" +
4666 " 2. It can lead to more wastage because of mmap page alignment\n" +
4667 " requirements\n" +
4668 " 3. It causes malloc performance to be more dependent on host\n" +
4669 " system memory management support routines which may vary in\n" +
4670 " implementation quality and may impose arbitrary\n" +
4671 " limitations. Generally, servicing a request via normal\n" +
4672 " malloc steps is faster than going through a system's mmap.\n" +
4673 "\n" +
4674 " The advantages of mmap nearly always outweigh disadvantages for\n" +
4675 " \"large\" chunks, but the value of \"large\" varies across systems. The\n" +
4676 " default is an empirically derived value that works well in most\n" +
4677 " systems.\n" +
4678 "*/\n" +
4679 "\n" +
4680 "#define M_MMAP_THRESHOLD -3\n" +
4681 "\n" +
4682 "#ifndef DEFAULT_MMAP_THRESHOLD\n" +
4683 "#define DEFAULT_MMAP_THRESHOLD (256 * 1024)\n" +
4684 "#endif\n" +
4685 "\n" +
4686 "/*\n" +
4687 " M_MMAP_MAX is the maximum number of requests to simultaneously\n" +
4688 " service using mmap. This parameter exists because\n" +
4689 ". Some systems have a limited number of internal tables for\n" +
4690 " use by mmap, and using more than a few of them may degrade\n" +
4691 " performance.\n" +
4692 "\n" +
4693 " The default is set to a value that serves only as a safeguard.\n" +
4694 " Setting to 0 disables use of mmap for servicing large requests. If\n" +
4695 " HAVE_MMAP is not set, the default value is 0, and attempts to set it\n" +
4696 " to non-zero values in mallopt will fail.\n" +
4697 "*/\n" +
4698 "\n" +
4699 "#define M_MMAP_MAX -4\n" +
4700 "\n") +
4701 ("#ifndef DEFAULT_MMAP_MAX\n" +
4702 "#if HAVE_MMAP\n" +
4703 "#define DEFAULT_MMAP_MAX (65536)\n" +
4704 "#else\n" +
4705 "#define DEFAULT_MMAP_MAX (0)\n" +
4706 "#endif\n" +
4707 "#endif\n" +
4708 "\n" +
4709 "/*\n" +
4710 " ========================================================================\n" +
4711 " To make a fully customizable malloc.h header file, cut everything\n" +
4712 " above this line, put into file malloc.h, edit to suit, and #include it\n" +
4713 " on the next line, as well as in programs that use this malloc.\n" +
4714 " ========================================================================\n" +
4715 "*/\n" +
4716 "\n" +
4717 "/* #include \"malloc.h\" */\n" +
4718 "\n" +
4719 "/* --------------------- public wrappers ---------------------- */\n" +
4720 "\n" +
4721 "#ifdef USE_PUBLIC_MALLOC_WRAPPERS\n" +
4722 "\n" +
4723 "/* Declare all routines as internal */\n" +
4724 "#if __STD_C\n" +
4725 "static Void_t* mALLOc(size_t);\n" +
4726 "static void fREe(Void_t*);\n" +
4727 "static Void_t* rEALLOc(Void_t*, size_t);\n" +
4728 "static Void_t* mEMALIGn(size_t, size_t);\n" +
4729 "static Void_t* vALLOc(size_t);\n" +
4730 "static Void_t* pVALLOc(size_t);\n" +
4731 "static Void_t* cALLOc(size_t, size_t);\n" +
4732 "static Void_t** iCALLOc(size_t, size_t, Void_t**);\n" +
4733 "static Void_t** iCOMALLOc(size_t, size_t*, Void_t**);\n" +
4734 "static void cFREe(Void_t*);\n" +
4735 "static int mTRIm(size_t);\n" +
4736 "static size_t mUSABLe(Void_t*);\n" +
4737 "static void mSTATs();\n" +
4738 "static int mALLOPt(int, int);\n" +
4739 "static struct mallinfo mALLINFo(void);\n" +
4740 "#else\n" +
4741 "static Void_t* mALLOc();\n" +
4742 "static void fREe();\n" +
4743 "static Void_t* rEALLOc();\n" +
4744 "static Void_t* mEMALIGn();\n" +
4745 "static Void_t* vALLOc();\n" +
4746 "static Void_t* pVALLOc();\n" +
4747 "static Void_t* cALLOc();\n" +
4748 "static Void_t** iCALLOc();\n" +
4749 "static Void_t** iCOMALLOc();\n" +
4750 "static void cFREe();\n" +
4751 "static int mTRIm();\n" +
4752 "static size_t mUSABLe();\n" +
4753 "static void mSTATs();\n" +
4754 "static int mALLOPt();\n" +
4755 "static struct mallinfo mALLINFo();\n" +
4756 "#endif\n" +
4757 "\n" +
4758 "/*\n" +
4759 " MALLOC_PREACTION and MALLOC_POSTACTION should be\n" +
4760 " defined to return 0 on success, and nonzero on failure.\n" +
4761 " The return value of MALLOC_POSTACTION is currently ignored\n" +
4762 " in wrapper functions since there is no reasonable default\n" +
4763 " action to take on failure.\n" +
4764 "*/\n" +
4765 "\n" +
4766 "\n" +
4767 "#ifdef USE_MALLOC_LOCK\n" +
4768 "\n" +
4769 "#ifdef WIN32\n" +
4770 "\n" +
4771 "static int mALLOC_MUTEx;\n" +
4772 "#define MALLOC_PREACTION slwait(&mALLOC_MUTEx)\n" +
4773 "#define MALLOC_POSTACTION slrelease(&mALLOC_MUTEx)\n" +
4774 "\n" +
4775 "#else\n" +
4776 "\n" +
4777 "#include <pthread.h>\n" +
4778 "\n" +
4779 "static pthread_mutex_t mALLOC_MUTEx = PTHREAD_MUTEX_INITIALIZER;\n" +
4780 "\n" +
4781 "#define MALLOC_PREACTION pthread_mutex_lock(&mALLOC_MUTEx)\n" +
4782 "#define MALLOC_POSTACTION pthread_mutex_unlock(&mALLOC_MUTEx)\n" +
4783 "\n" +
4784 "#endif /* USE_MALLOC_LOCK */\n" +
4785 "\n" +
4786 "#else\n" +
4787 "\n" +
4788 "/* Substitute anything you like for these */\n" +
4789 "\n" +
4790 "#define MALLOC_PREACTION (0)\n" +
4791 "#define MALLOC_POSTACTION (0)\n" +
4792 "\n" +
4793 "#endif\n" +
4794 "\n" +
4795 "Void_t* public_mALLOc(size_t bytes) {\n" +
4796 " Void_t* m;\n" +
4797 " if (MALLOC_PREACTION != 0) {\n" +
4798 " return 0;\n" +
4799 " }\n" +
4800 " m = mALLOc(bytes);\n" +
4801 " if (MALLOC_POSTACTION != 0) {\n" +
4802 " }\n" +
4803 " return m;\n" +
4804 "}\n" +
4805 "\n" +
4806 "\n" +
4807 "static pthread_once_t free_mutex_once = PTHREAD_ONCE_INIT;\n" +
4808 "static pthread_mutex_t free_mutex;\n" +
4809 "static int scheduled_free_size;\n" +
4810 "static int scheduled_free_capacity;\n" +
4811 "static int scheduled_free_list;\n" +
4812 "bool free_is_scheduled;\n" +
4813 "\n" +
4814 "static void initialize_scheduled_free_list()\n" +
4815 "{\n" +
4816 " pthread_mutex_init(&free_mutex, NULL);\n" +
4817 "}\n" +
4818 "\n" +
4819 "static void drain_scheduled_free_list()\n" +
4820 "{\n" +
4821 " pthread_mutex_lock(&free_mutex);\n" +
4822 " if (free_is_scheduled) {\n" +
4823 " for(int i = 0; i < scheduled_free_size; i++) {\n" +
4824 " main_thread_free(scheduled_free_list[i]);\n" +
4825 " }\n" +
4826 " free(scheduled_free_list);\n" +
4827 " scheduled_free_list = NULL;\n" +
4828 " scheduled_free_size = 0;\n" +
4829 " scheduled_free_capacity = 0;\n" +
4830 " free_is_scheduled = false;\n" +
4831 " }\n" +
4832 " pthread_mutex_unlock(&free_mutex);\n" +
4833 "}\n" +
4834 "\n" +
4835 "static void schedule_free_on_main_thread(Void_t* m)\n" +
4836 "{\n" +
4837 " pthread_once(&free_mutex_once, initialize_scheduled_free_list);\n" +
4838 "\n" +
4839 " pthread_mutex_lock(&free_mutex);\n" +
4840 " if (scheduled_free_size == scheduled_free_capacity) {\n" +
4841 … scheduled_free_capacity = scheduled_free_capacity == 0 ? 16 : scheduled_free_capacity * 1.2;\n" +
4842 …free_list = (Void_t**)realloc(scheduled_free_list, sizeof(Void_t*) * scheduled_free_capacity);\n" +
4843 " }\n" +
4844 " scheduled_free_list[scheduled_free_size++] = m;\n" +
4845 " if (!free_is_scheduled) {\n" +
4846 " QTimer::immediateSingleShotOnMainThread(0, drain_scheduled_free_list);\n" +
4847 " free_is_scheduled = true;\n" +
4848 " }\n" +
4849 " pthread_mutex_unlock(&free_mutex);\n" +
4850 "}\n") +
4851 ("\n" +
4852 "void public_fREe(Void_t* m) {\n" +
4853 " if (!pthread_main_np()) {\n" +
4854 " schedule_free_on_main_thread(m);\n" +
4855 " return;\n" +
4856 " }\n" +
4857 "\n" +
4858 " if (MALLOC_PREACTION != 0) {\n" +
4859 " return;\n" +
4860 " }\n" +
4861 " fREe(m);\n" +
4862 " if (MALLOC_POSTACTION != 0) {\n" +
4863 " }\n" +
4864 "}\n" +
4865 "\n" +
4866 "Void_t* public_rEALLOc(Void_t* m, size_t bytes) {\n" +
4867 " if (MALLOC_PREACTION != 0) {\n" +
4868 " return 0;\n" +
4869 " }\n" +
4870 " m = rEALLOc(m, bytes);\n" +
4871 " if (MALLOC_POSTACTION != 0) {\n" +
4872 " }\n" +
4873 " return m;\n" +
4874 "}\n" +
4875 "\n" +
4876 "Void_t* public_mEMALIGn(size_t alignment, size_t bytes) {\n" +
4877 " Void_t* m;\n" +
4878 " if (MALLOC_PREACTION != 0) {\n" +
4879 " return 0;\n" +
4880 " }\n" +
4881 " m = mEMALIGn(alignment, bytes);\n" +
4882 " if (MALLOC_POSTACTION != 0) {\n" +
4883 " }\n" +
4884 " return m;\n" +
4885 "}\n" +
4886 "\n" +
4887 "Void_t* public_vALLOc(size_t bytes) {\n" +
4888 " Void_t* m;\n" +
4889 " if (MALLOC_PREACTION != 0) {\n" +
4890 " return 0;\n" +
4891 " }\n" +
4892 " m = vALLOc(bytes);\n" +
4893 " if (MALLOC_POSTACTION != 0) {\n" +
4894 " }\n" +
4895 " return m;\n" +
4896 "}\n" +
4897 "\n" +
4898 "Void_t* public_pVALLOc(size_t bytes) {\n" +
4899 " Void_t* m;\n" +
4900 " if (MALLOC_PREACTION != 0) {\n" +
4901 " return 0;\n" +
4902 " }\n" +
4903 " m = pVALLOc(bytes);\n" +
4904 " if (MALLOC_POSTACTION != 0) {\n" +
4905 " }\n" +
4906 " return m;\n" +
4907 "}\n" +
4908 "\n" +
4909 "Void_t* public_cALLOc(size_t n, size_t elem_size) {\n" +
4910 " Void_t* m;\n" +
4911 " if (MALLOC_PREACTION != 0) {\n" +
4912 " return 0;\n" +
4913 " }\n" +
4914 " m = cALLOc(n, elem_size);\n" +
4915 " if (MALLOC_POSTACTION != 0) {\n" +
4916 " }\n" +
4917 " return m;\n" +
4918 "}\n" +
4919 "\n" +
4920 "\n" +
4921 "Void_t** public_iCALLOc(size_t n, size_t elem_size, Void_t** chunks) {\n" +
4922 " Void_t** m;\n" +
4923 " if (MALLOC_PREACTION != 0) {\n" +
4924 " return 0;\n" +
4925 " }\n" +
4926 " m = iCALLOc(n, elem_size, chunks);\n" +
4927 " if (MALLOC_POSTACTION != 0) {\n" +
4928 " }\n" +
4929 " return m;\n" +
4930 "}\n" +
4931 "\n" +
4932 "Void_t** public_iCOMALLOc(size_t n, size_t sizes[], Void_t** chunks) {\n" +
4933 " Void_t** m;\n" +
4934 " if (MALLOC_PREACTION != 0) {\n" +
4935 " return 0;\n" +
4936 " }\n" +
4937 " m = iCOMALLOc(n, sizes, chunks);\n" +
4938 " if (MALLOC_POSTACTION != 0) {\n" +
4939 " }\n" +
4940 " return m;\n" +
4941 "}\n" +
4942 "\n" +
4943 "void public_cFREe(Void_t* m) {\n" +
4944 " if (MALLOC_PREACTION != 0) {\n" +
4945 " return;\n" +
4946 " }\n" +
4947 " cFREe(m);\n" +
4948 " if (MALLOC_POSTACTION != 0) {\n" +
4949 " }\n" +
4950 "}\n" +
4951 "\n" +
4952 "int public_mTRIm(size_t s) {\n" +
4953 " int result;\n" +
4954 " if (MALLOC_PREACTION != 0) {\n" +
4955 " return 0;\n" +
4956 " }\n" +
4957 " result = mTRIm(s);\n" +
4958 " if (MALLOC_POSTACTION != 0) {\n" +
4959 " }\n" +
4960 " return result;\n" +
4961 "}\n" +
4962 "\n" +
4963 "size_t public_mUSABLe(Void_t* m) {\n" +
4964 " size_t result;\n" +
4965 " if (MALLOC_PREACTION != 0) {\n" +
4966 " return 0;\n" +
4967 " }\n" +
4968 " result = mUSABLe(m);\n" +
4969 " if (MALLOC_POSTACTION != 0) {\n" +
4970 " }\n" +
4971 " return result;\n" +
4972 "}\n" +
4973 "\n" +
4974 "void public_mSTATs() {\n" +
4975 " if (MALLOC_PREACTION != 0) {\n" +
4976 " return;\n" +
4977 " }\n" +
4978 " mSTATs();\n" +
4979 " if (MALLOC_POSTACTION != 0) {\n" +
4980 " }\n" +
4981 "}\n" +
4982 "\n" +
4983 "struct mallinfo public_mALLINFo() {\n" +
4984 " struct mallinfo m;\n" +
4985 " if (MALLOC_PREACTION != 0) {\n" +
4986 " struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n" +
4987 " return nm;\n" +
4988 " }\n" +
4989 " m = mALLINFo();\n" +
4990 " if (MALLOC_POSTACTION != 0) {\n" +
4991 " }\n" +
4992 " return m;\n" +
4993 "}\n" +
4994 "\n" +
4995 "int public_mALLOPt(int p, int v) {\n" +
4996 " int result;\n" +
4997 " if (MALLOC_PREACTION != 0) {\n" +
4998 " return 0;\n" +
4999 " }\n" +
5000 " result = mALLOPt(p, v);\n" +
5001 " if (MALLOC_POSTACTION != 0) {\n" +
5002 " }\n" +
5003 " return result;\n" +
5004 "}\n" +
5005 "\n") +
5006 ("#endif\n" +
5007 "\n" +
5008 "\n" +
5009 "\n" +
5010 "/* ------------- Optional versions of memcopy ---------------- */\n" +
5011 "\n" +
5012 "\n" +
5013 "#if USE_MEMCPY\n" +
5014 "\n" +
5015 "/*\n" +
5016 " Note: memcpy is ONLY invoked with non-overlapping regions,\n" +
5017 " so the (usually slower) memmove is not needed.\n" +
5018 "*/\n" +
5019 "\n" +
5020 "#define MALLOC_COPY(dest, src, nbytes) memcpy(dest, src, nbytes)\n" +
5021 "#define MALLOC_ZERO(dest, nbytes) memset(dest, 0, nbytes)\n" +
5022 "\n" +
5023 "#else /* !USE_MEMCPY */\n" +
5024 "\n" +
5025 "/* Use Duff's device for good zeroing/copying performance. */\n" +
5026 "\n" +
5027 "#define MALLOC_ZERO(charp, nbytes) \\n" +
5028 "do { \\n" +
5029 " INTERNAL_SIZE_T* mzp = (INTERNAL_SIZE_T*)(charp); \\n" +
5030 " CHUNK_SIZE_T mctmp = (nbytes)/sizeof(INTERNAL_SIZE_T); \\n" +
5031 " long mcn; \\n" +
5032 " if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp %= 8; } \\n" +
5033 " switch (mctmp) { \\n" +
5034 " case 0: for(;;) { *mzp++ = 0; \\n" +
5035 " case 7: *mzp++ = 0; \\n" +
5036 " case 6: *mzp++ = 0; \\n" +
5037 " case 5: *mzp++ = 0; \\n" +
5038 " case 4: *mzp++ = 0; \\n" +
5039 " case 3: *mzp++ = 0; \\n" +
5040 " case 2: *mzp++ = 0; \\n" +
5041 " case 1: *mzp++ = 0; if(mcn <= 0) break; mcn--; } \\n" +
5042 " } \\n" +
5043 "} while(0)\n" +
5044 "\n" +
5045 "#define MALLOC_COPY(dest,src,nbytes) \\n" +
5046 "do { \\n" +
5047 " INTERNAL_SIZE_T* mcsrc = (INTERNAL_SIZE_T*) src; \\n" +
5048 " INTERNAL_SIZE_T* mcdst = (INTERNAL_SIZE_T*) dest; \\n" +
5049 " CHUNK_SIZE_T mctmp = (nbytes)/sizeof(INTERNAL_SIZE_T); \\n" +
5050 " long mcn; \\n" +
5051 " if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp %= 8; } \\n" +
5052 " switch (mctmp) { \\n" +
5053 " case 0: for(;;) { *mcdst++ = *mcsrc++; \\n" +
5054 " case 7: *mcdst++ = *mcsrc++; \\n" +
5055 " case 6: *mcdst++ = *mcsrc++; \\n" +
5056 " case 5: *mcdst++ = *mcsrc++; \\n" +
5057 " case 4: *mcdst++ = *mcsrc++; \\n" +
5058 " case 3: *mcdst++ = *mcsrc++; \\n" +
5059 " case 2: *mcdst++ = *mcsrc++; \\n" +
5060 " case 1: *mcdst++ = *mcsrc++; if(mcn <= 0) break; mcn--; } \\n" +
5061 " } \\n" +
5062 "} while(0)\n" +
5063 "\n" +
5064 "#endif\n" +
5065 "\n" +
5066 "/* ------------------ MMAP support ------------------ */\n" +
5067 "\n" +
5068 "\n" +
5069 "#if HAVE_MMAP\n" +
5070 "\n" +
5071 "#ifndef LACKS_FCNTL_H\n" +
5072 "#include <fcntl.h>\n" +
5073 "#endif\n" +
5074 "\n" +
5075 "#ifndef LACKS_SYS_MMAN_H\n" +
5076 "#include <sys/mman.h>\n" +
5077 "#endif\n" +
5078 "\n" +
5079 "#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)\n" +
5080 "#define MAP_ANONYMOUS MAP_ANON\n" +
5081 "#endif\n" +
5082 "\n" +
5083 "/*\n" +
5084 " Nearly all versions of mmap support MAP_ANONYMOUS,\n" +
5085 " so the following is unlikely to be needed, but is\n" +
5086 " supplied just in case.\n" +
5087 "*/\n" +
5088 "\n" +
5089 "#ifndef MAP_ANONYMOUS\n" +
5090 "\n" +
5091 "static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */\n" +
5092 "\n" +
5093 "#define MMAP(addr, size, prot, flags) ((dev_zero_fd < 0) ? \\n" +
5094 " (dev_zero_fd = open(\"/dev/zero\", O_RDWR), \\n" +
5095 " mmap((addr), (size), (prot), (flags), dev_zero_fd, 0)) : \\n" +
5096 " mmap((addr), (size), (prot), (flags), dev_zero_fd, 0))\n" +
5097 "\n" +
5098 "#else\n" +
5099 "\n" +
5100 "#define MMAP(addr, size, prot, flags) \\n" +
5101 " (mmap((addr), (size), (prot), (flags)|MAP_ANONYMOUS, -1, 0))\n" +
5102 "\n" +
5103 "#endif\n" +
5104 "\n" +
5105 "\n" +
5106 "#endif /* HAVE_MMAP */\n" +
5107 "\n" +
5108 "\n" +
5109 "/*\n" +
5110 " ----------------------- Chunk representations -----------------------\n" +
5111 "*/\n" +
5112 "\n" +
5113 "\n" +
5114 "/*\n" +
5115 " This struct declaration is misleading (but accurate and necessary).\n" +
5116 " It declares a \"view\" into memory allowing access to necessary\n" +
5117 " fields at known offsets from a given base. See explanation below.\n" +
5118 "*/\n" +
5119 "\n" +
5120 "struct malloc_chunk {\n" +
5121 "\n" +
5122 " INTERNAL_SIZE_T prev_size; /* Size of previous chunk (if free). */\n" +
5123 " INTERNAL_SIZE_T size; /* Size in bytes, including overhead. */\n" +
5124 "\n" +
5125 " struct malloc_chunk* fd; /* double links -- used only if free. */\n" +
5126 " struct malloc_chunk* bk;\n" +
5127 "};\n" +
5128 "\n" +
5129 "\n" +
5130 "typedef struct malloc_chunk* mchunkptr;\n" +
5131 "\n" +
5132 "/*\n" +
5133 " malloc_chunk details:\n" +
5134 "\n" +
5135 " (The following includes lightly edited explanations by Colin Plumb.)\n" +
5136 "\n" +
5137 " Chunks of memory are maintained using a `boundary tag' method as\n" +
5138 " described in e.g., Knuth or Standish. (See the paper by Paul\n" +
5139 " Wilson ftp://ftp.cs.utexas.edu/pub/garbage/allocsrv.ps for a\n" +
5140 " survey of such techniques.) Sizes of free chunks are stored both\n" +
5141 " in the front of each chunk and at the end. This makes\n" +
5142 " consolidating fragmented chunks into bigger chunks very fast. The\n" +
5143 " size fields also hold bits representing whether chunks are free or\n" +
5144 " in use.\n" +
5145 "\n" +
5146 " An allocated chunk looks like this:\n" +
5147 "\n" +
5148 "\n" +
5149 " chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" +
5150 " | Size of previous chunk, if allocated | |\n" +
5151 " +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" +
5152 " | Size of chunk, in bytes |P|\n" +
5153 " mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" +
5154 " | User data starts here... .\n" +
5155 " . .\n" +
5156 " . (malloc_usable_space() bytes) .\n" +
5157 " . |\n" +
5158 "nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" +
5159 " | Size of chunk |\n" +
5160 " +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" +
5161 "\n") +
5162 ("\n" +
5163 " Where \"chunk\" is the front of the chunk for the purpose of most of\n" +
5164 " the malloc code, but \"mem\" is the pointer that is returned to the\n" +
5165 " user. \"Nextchunk\" is the beginning of the next contiguous chunk.\n" +
5166 "\n" +
5167 " Chunks always begin on even word boundries, so the mem portion\n" +
5168 " (which is returned to the user) is also on an even word boundary, and\n" +
5169 " thus at least double-word aligned.\n" +
5170 "\n" +
5171 " Free chunks are stored in circular doubly-linked lists, and look like this:\n" +
5172 "\n" +
5173 " chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" +
5174 " | Size of previous chunk |\n" +
5175 " +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" +
5176 " `head:' | Size of chunk, in bytes |P|\n" +
5177 " mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" +
5178 " | Forward pointer to next chunk in list |\n" +
5179 " +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" +
5180 " | Back pointer to previous chunk in list |\n" +
5181 " +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" +
5182 " | Unused space (may be 0 bytes long) .\n" +
5183 " . .\n" +
5184 " . |\n" +
5185 "nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" +
5186 " `foot:' | Size of chunk, in bytes |\n" +
5187 " +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" +
5188 "\n" +
5189 " The P (PREV_INUSE) bit, stored in the unused low-order bit of the\n" +
5190 " chunk size (which is always a multiple of two words), is an in-use\n" +
5191 " bit for the *previous* chunk. If that bit is *clear*, then the\n" +
5192 " word before the current chunk size contains the previous chunk\n" +
5193 " size, and can be used to find the front of the previous chunk.\n" +
5194 " The very first chunk allocated always has this bit set,\n" +
5195 " preventing access to non-existent (or non-owned) memory. If\n" +
5196 " prev_inuse is set for any given chunk, then you CANNOT determine\n" +
5197 " the size of the previous chunk, and might even get a memory\n" +
5198 " addressing fault when trying to do so.\n" +
5199 "\n" +
5200 " Note that the `foot' of the current chunk is actually represented\n" +
5201 " as the prev_size of the NEXT chunk. This makes it easier to\n" +
5202 " deal with alignments etc but can be very confusing when trying\n" +
5203 " to extend or adapt this code.\n" +
5204 "\n" +
5205 " The two exceptions to all this are\n" +
5206 "\n" +
5207 " 1. The special chunk `top' doesn't bother using the\n" +
5208 " trailing size field since there is no next contiguous chunk\n" +
5209 " that would have to index off it. After initialization, `top'\n" +
5210 " is forced to always exist. If it would become less than\n" +
5211 " MINSIZE bytes long, it is replenished.\n" +
5212 "\n" +
5213 " 2. Chunks allocated via mmap, which have the second-lowest-order\n" +
5214 " bit (IS_MMAPPED) set in their size fields. Because they are\n" +
5215 " allocated one-by-one, each must contain its own trailing size field.\n" +
5216 "\n" +
5217 "*/\n" +
5218 "\n" +
5219 "/*\n" +
5220 " ---------- Size and alignment checks and conversions ----------\n" +
5221 "*/\n" +
5222 "\n" +
5223 "/* conversion from malloc headers to user pointers, and back */\n" +
5224 "\n" +
5225 "#define chunk2mem(p) ((Void_t*)((char*)(p) + 2*SIZE_SZ))\n" +
5226 "#define mem2chunk(mem) ((mchunkptr)((char*)(mem) - 2*SIZE_SZ))\n" +
5227 "\n" +
5228 "/* The smallest possible chunk */\n" +
5229 "#define MIN_CHUNK_SIZE (sizeof(struct malloc_chunk))\n" +
5230 "\n" +
5231 "/* The smallest size we can malloc is an aligned minimal chunk */\n" +
5232 "\n" +
5233 "#define MINSIZE \\n" +
5234 " (CHUNK_SIZE_T)(((MIN_CHUNK_SIZE+MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK))\n" +
5235 "\n" +
5236 "/* Check if m has acceptable alignment */\n" +
5237 "\n" +
5238 "#define aligned_OK(m) (((PTR_UINT)((m)) & (MALLOC_ALIGN_MASK)) == 0)\n" +
5239 "\n" +
5240 "\n" +
5241 "/*\n" +
5242 " Check if a request is so large that it would wrap around zero when\n" +
5243 " padded and aligned. To simplify some other code, the bound is made\n" +
5244 " low enough so that adding MINSIZE will also not wrap around sero.\n" +
5245 "*/\n" +
5246 "\n" +
5247 "#define REQUEST_OUT_OF_RANGE(req) \\n" +
5248 " ((CHUNK_SIZE_T)(req) >= \\n" +
5249 " (CHUNK_SIZE_T)(INTERNAL_SIZE_T)(-2 * MINSIZE))\n" +
5250 "\n" +
5251 "/* pad request bytes into a usable size -- internal version */\n" +
5252 "\n" +
5253 "#define request2size(req) \\n" +
5254 " (((req) + SIZE_SZ + MALLOC_ALIGN_MASK < MINSIZE) ? \\n" +
5255 " MINSIZE : \\n" +
5256 " ((req) + SIZE_SZ + MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK)\n" +
5257 "\n" +
5258 "/* Same, except also perform argument check */\n" +
5259 "\n" +
5260 "#define checked_request2size(req, sz) \\n" +
5261 " if (REQUEST_OUT_OF_RANGE(req)) { \\n" +
5262 " MALLOC_FAILURE_ACTION; \\n" +
5263 " return 0; \\n" +
5264 " } \\n" +
5265 " (sz) = request2size(req);\n" +
5266 "\n" +
5267 "/*\n" +
5268 " --------------- Physical chunk operations ---------------\n" +
5269 "*/\n" +
5270 "\n" +
5271 "\n" +
5272 "/* size field is or'ed with PREV_INUSE when previous adjacent chunk in use */\n" +
5273 "#define PREV_INUSE 0x1\n" +
5274 "\n" +
5275 "/* extract inuse bit of previous chunk */\n" +
5276 "#define prev_inuse(p) ((p)->size & PREV_INUSE)\n" +
5277 "\n" +
5278 "\n" +
5279 "/* size field is or'ed with IS_MMAPPED if the chunk was obtained with mmap() */\n" +
5280 "#define IS_MMAPPED 0x2\n" +
5281 "\n" +
5282 "/* check for mmap()'ed chunk */\n" +
5283 "#define chunk_is_mmapped(p) ((p)->size & IS_MMAPPED)\n" +
5284 "\n" +
5285 "/*\n" +
5286 " Bits to mask off when extracting size\n" +
5287 "\n" +
5288 " Note: IS_MMAPPED is intentionally not masked off from size field in\n" +
5289 " macros for which mmapped chunks should never be seen. This should\n" +
5290 " cause helpful core dumps to occur if it is tried by accident by\n" +
5291 " people extending or adapting this malloc.\n" +
5292 "*/\n" +
5293 "#define SIZE_BITS (PREV_INUSE|IS_MMAPPED)\n" +
5294 "\n" +
5295 "/* Get size, ignoring use bits */\n" +
5296 "#define chunksize(p) ((p)->size & ~(SIZE_BITS))\n" +
5297 "\n" +
5298 "\n" +
5299 "/* Ptr to next physical malloc_chunk. */\n" +
5300 "#define next_chunk(p) ((mchunkptr)( ((char*)(p)) + ((p)->size & ~PREV_INUSE) ))\n" +
5301 "\n" +
5302 "/* Ptr to previous physical malloc_chunk */\n" +
5303 "#define prev_chunk(p) ((mchunkptr)( ((char*)(p)) - ((p)->prev_size) ))\n" +
5304 "\n" +
5305 "/* Treat space at ptr + offset as a chunk */\n" +
5306 "#define chunk_at_offset(p, s) ((mchunkptr)(((char*)(p)) + (s)))\n" +
5307 "\n" +
5308 "/* extract p's inuse bit */\n" +
5309 "#define inuse(p)\\n" +
5310 "((((mchunkptr)(((char*)(p))+((p)->size & ~PREV_INUSE)))->size) & PREV_INUSE)\n" +
5311 "\n" +
5312 "/* set/clear chunk as being inuse without otherwise disturbing */\n" +
5313 "#define set_inuse(p)\\n" +
5314 "((mchunkptr)(((char*)(p)) + ((p)->size & ~PREV_INUSE)))->size |= PREV_INUSE\n" +
5315 "\n") +
5316 ("#define clear_inuse(p)\\n" +
5317 "((mchunkptr)(((char*)(p)) + ((p)->size & ~PREV_INUSE)))->size &= ~(PREV_INUSE)\n" +
5318 "\n" +
5319 "\n" +
5320 "/* check/set/clear inuse bits in known places */\n" +
5321 "#define inuse_bit_at_offset(p, s)\\n" +
5322 " (((mchunkptr)(((char*)(p)) + (s)))->size & PREV_INUSE)\n" +
5323 "\n" +
5324 "#define set_inuse_bit_at_offset(p, s)\\n" +
5325 " (((mchunkptr)(((char*)(p)) + (s)))->size |= PREV_INUSE)\n" +
5326 "\n" +
5327 "#define clear_inuse_bit_at_offset(p, s)\\n" +
5328 " (((mchunkptr)(((char*)(p)) + (s)))->size &= ~(PREV_INUSE))\n" +
5329 "\n" +
5330 "\n" +
5331 "/* Set size at head, without disturbing its use bit */\n" +
5332 "#define set_head_size(p, s) ((p)->size = (((p)->size & PREV_INUSE) | (s)))\n" +
5333 "\n" +
5334 "/* Set size/use field */\n" +
5335 "#define set_head(p, s) ((p)->size = (s))\n" +
5336 "\n" +
5337 "/* Set size at footer (only when chunk is not in use) */\n" +
5338 "#define set_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_size = (s))\n" +
5339 "\n" +
5340 "\n" +
5341 "/*\n" +
5342 " -------------------- Internal data structures --------------------\n" +
5343 "\n" +
5344 " All internal state is held in an instance of malloc_state defined\n" +
5345 " below. There are no other static variables, except in two optional\n" +
5346 " cases:\n" +
5347 " * If USE_MALLOC_LOCK is defined, the mALLOC_MUTEx declared above.\n" +
5348 " * If HAVE_MMAP is true, but mmap doesn't support\n" +
5349 " MAP_ANONYMOUS, a dummy file descriptor for mmap.\n" +
5350 "\n" +
5351 " Beware of lots of tricks that minimize the total bookkeeping space\n" +
5352 " requirements. The result is a little over 1K bytes (for 4byte\n" +
5353 " pointers and size_t.)\n" +
5354 "*/\n" +
5355 "\n" +
5356 "/*\n" +
5357 " Bins\n" +
5358 "\n" +
5359 " An array of bin headers for free chunks. Each bin is doubly\n" +
5360 " linked. The bins are approximately proportionally (log) spaced.\n" +
5361 " There are a lot of these bins (128). This may look excessive, but\n" +
5362 " works very well in practice. Most bins hold sizes that are\n" +
5363 " unusual as malloc request sizes, but are more usual for fragments\n" +
5364 " and consolidated sets of chunks, which is what these bins hold, so\n" +
5365 " they can be found quickly. All procedures maintain the invariant\n" +
5366 " that no consolidated chunk physically borders another one, so each\n" +
5367 " chunk in a list is known to be preceeded and followed by either\n" +
5368 " inuse chunks or the ends of memory.\n" +
5369 "\n" +
5370 " Chunks in bins are kept in size order, with ties going to the\n" +
5371 " approximately least recently used chunk. Ordering isn't needed\n" +
5372 " for the small bins, which all contain the same-sized chunks, but\n" +
5373 " facilitates best-fit allocation for larger chunks. These lists\n" +
5374 " are just sequential. Keeping them in order almost never requires\n" +
5375 " enough traversal to warrant using fancier ordered data\n" +
5376 " structures.\n" +
5377 "\n" +
5378 " Chunks of the same size are linked with the most\n" +
5379 " recently freed at the front, and allocations are taken from the\n" +
5380 " back. This results in LRU (FIFO) allocation order, which tends\n" +
5381 " to give each chunk an equal opportunity to be consolidated with\n" +
5382 " adjacent freed chunks, resulting in larger free chunks and less\n" +
5383 " fragmentation.\n" +
5384 "\n" +
5385 " To simplify use in double-linked lists, each bin header acts\n" +
5386 " as a malloc_chunk. This avoids special-casing for headers.\n" +
5387 " But to conserve space and improve locality, we allocate\n" +
5388 " only the fd/bk pointers of bins, and then use repositioning tricks\n" +
5389 " to treat these as the fields of a malloc_chunk*.\n" +
5390 "*/\n" +
5391 "\n" +
5392 "typedef struct malloc_chunk* mbinptr;\n" +
5393 "\n" +
5394 "/* addressing -- note that bin_at(0) does not exist */\n" +
5395 "#define bin_at(m, i) ((mbinptr)((char*)&((m)->bins[(i)<<1]) - (SIZE_SZ<<1)))\n" +
5396 "\n" +
5397 "/* analog of ++bin */\n" +
5398 "#define next_bin(b) ((mbinptr)((char*)(b) + (sizeof(mchunkptr)<<1)))\n" +
5399 "\n" +
5400 "/* Reminders about list directionality within bins */\n" +
5401 "#define first(b) ((b)->fd)\n" +
5402 "#define last(b) ((b)->bk)\n" +
5403 "\n" +
5404 "/* Take a chunk off a bin list */\n" +
5405 "#define unlink(P, BK, FD) { \\n" +
5406 " FD = P->fd; \\n" +
5407 " BK = P->bk; \\n" +
5408 " FD->bk = BK; \\n" +
5409 " BK->fd = FD; \\n" +
5410 "}\n" +
5411 "\n" +
5412 "/*\n" +
5413 " Indexing\n" +
5414 "\n" +
5415 " Bins for sizes < 512 bytes contain chunks of all the same size, spaced\n" +
5416 " 8 bytes apart. Larger bins are approximately logarithmically spaced:\n" +
5417 "\n" +
5418 " 64 bins of size 8\n" +
5419 " 32 bins of size 64\n" +
5420 " 16 bins of size 512\n" +
5421 " 8 bins of size 4096\n" +
5422 " 4 bins of size 32768\n" +
5423 " 2 bins of size 262144\n" +
5424 " 1 bin of size what's left\n" +
5425 "\n" +
5426 " The bins top out around 1MB because we expect to service large\n" +
5427 " requests via mmap.\n" +
5428 "*/\n" +
5429 "\n" +
5430 "#define NBINS 96\n" +
5431 "#define NSMALLBINS 32\n" +
5432 "#define SMALLBIN_WIDTH 8\n" +
5433 "#define MIN_LARGE_SIZE 256\n" +
5434 "\n" +
5435 "#define in_smallbin_range(sz) \\n" +
5436 " ((CHUNK_SIZE_T)(sz) < (CHUNK_SIZE_T)MIN_LARGE_SIZE)\n" +
5437 "\n" +
5438 "#define smallbin_index(sz) (((unsigned)(sz)) >> 3)\n" +
5439 "\n" +
5440 "/*\n" +
5441 " Compute index for size. We expect this to be inlined when\n" +
5442 " compiled with optimization, else not, which works out well.\n" +
5443 "*/\n" +
5444 "static int largebin_index(unsigned int sz) {\n" +
5445 " unsigned int x = sz >> SMALLBIN_WIDTH;\n" +
5446 " unsigned int m; /* bit position of highest set bit of m */\n" +
5447 "\n" +
5448 " if (x >= 0x10000) return NBINS-1;\n" +
5449 "\n" +
5450 " /* On intel, use BSRL instruction to find highest bit */\n" +
5451 "#if defined(__GNUC__) && defined(i386)\n" +
5452 "\n" +
5453 " __asm__(\"bsrl %1,%0\\n\\t\"\n" +
5454 " : \"=r\" (m)\n" +
5455 " : \"g\" (x));\n" +
5456 "\n" +
5457 "#else\n" +
5458 " {\n" +
5459 " /*\n" +
5460 " Based on branch-free nlz algorithm in chapter 5 of Henry\n" +
5461 " S. Warren Jr's book \"Hacker's Delight\".\n" +
5462 " */\n" +
5463 "\n" +
5464 " unsigned int n = ((x - 0x100) >> 16) & 8;\n" +
5465 " x <<= n;\n" +
5466 " m = ((x - 0x1000) >> 16) & 4;\n" +
5467 " n += m;\n" +
5468 " x <<= m;\n" +
5469 " m = ((x - 0x4000) >> 16) & 2;\n" +
5470 " n += m;\n" +
5471 " x = (x << m) >> 14;\n" +
5472 " m = 13 - n + (x & ~(x>>1));\n" +
5473 " }\n" +
5474 "#endif\n" +
5475 "\n") +
5477 " /* Use next 2 bits to create finer-granularity bins */\n" +
5478 " return NSMALLBINS + (m << 2) + ((sz >> (m + 6)) & 3);\n" +
5479 "}\n" +
5480 "\n" +
5481 "#define bin_index(sz) \\n" +
5482 " ((in_smallbin_range(sz)) ? smallbin_index(sz) : largebin_index(sz))\n" +
5483 "\n" +
5484 "/*\n" +
5485 " FIRST_SORTED_BIN_SIZE is the chunk size corresponding to the\n" +
5486 " first bin that is maintained in sorted order. This must\n" +
5487 " be the smallest size corresponding to a given bin.\n" +
5488 "\n" +
5489 " Normally, this should be MIN_LARGE_SIZE. But you can weaken\n" +
5490 " best fit guarantees to sometimes speed up malloc by increasing value.\n" +
5491 " Doing this means that malloc may choose a chunk that is\n" +
5492 " non-best-fitting by up to the width of the bin.\n" +
5493 "\n" +
5494 " Some useful cutoff values:\n" +
5495 " 512 - all bins sorted\n" +
5496 " 2560 - leaves bins <= 64 bytes wide unsorted\n" +
5497 " 12288 - leaves bins <= 512 bytes wide unsorted\n" +
5498 " 65536 - leaves bins <= 4096 bytes wide unsorted\n" +
5499 " 262144 - leaves bins <= 32768 bytes wide unsorted\n" +
5500 " -1 - no bins sorted (not recommended!)\n" +
5501 "*/\n" +
5502 "\n" +
5503 "#define FIRST_SORTED_BIN_SIZE MIN_LARGE_SIZE\n" +
5504 "/* #define FIRST_SORTED_BIN_SIZE 65536 */\n" +
5505 "\n" +
5506 "/*\n" +
5507 " Unsorted chunks\n" +
5508 "\n" +
5509 " All remainders from chunk splits, as well as all returned chunks,\n" +
5510 " are first placed in the \"unsorted\" bin. They are then placed\n" +
5511 " in regular bins after malloc gives them ONE chance to be used before\n" +
5512 " binning. So, basically, the unsorted_chunks list acts as a queue,\n" +
5513 " with chunks being placed on it in free (and malloc_consolidate),\n" +
5514 " and taken off (to be either used or placed in bins) in malloc.\n" +
5515 "*/\n" +
5516 "\n" +
5517 "/* The otherwise unindexable 1-bin is used to hold unsorted chunks. */\n" +
5518 "#define unsorted_chunks(M) (bin_at(M, 1))\n" +
5519 "\n" +
5520 "/*\n" +
5521 " Top\n" +
5522 "\n" +
5523 " The top-most available chunk (i.e., the one bordering the end of\n" +
5524 " available memory) is treated specially. It is never included in\n" +
5525 " any bin, is used only if no other chunk is available, and is\n" +
5526 " released back to the system if it is very large (see\n" +
5527 " M_TRIM_THRESHOLD). Because top initially\n" +
5528 " points to its own bin with initial zero size, thus forcing\n" +
5529 " extension on the first malloc request, we avoid having any special\n" +
5530 " code in malloc to check whether it even exists yet. But we still\n" +
5531 " need to do so when getting memory from system, so we make\n" +
5532 " initial_top treat the bin as a legal but unusable chunk during the\n" +
5533 " interval between initialization and the first call to\n" +
5534 " sYSMALLOc. (This is somewhat delicate, since it relies on\n" +
5535 " the 2 preceding words to be zero during this interval as well.)\n" +
5536 "*/\n" +
5537 "\n" +
5538 "/* Conveniently, the unsorted bin can be used as dummy top on first call */\n" +
5539 "#define initial_top(M) (unsorted_chunks(M))\n" +
5540 "\n" +
5541 "/*\n" +
5542 " Binmap\n" +
5543 "\n" +
5544 " To help compensate for the large number of bins, a one-level index\n" +
5545 " structure is used for bin-by-bin searching. `binmap' is a\n" +
5546 " bitvector recording whether bins are definitely empty so they can\n" +
5547 " be skipped over during during traversals. The bits are NOT always\n" +
5548 " cleared as soon as bins are empty, but instead only\n" +
5549 " when they are noticed to be empty during traversal in malloc.\n" +
5550 "*/\n" +
5551 "\n" +
5552 "/* Conservatively use 32 bits per map word, even if on 64bit system */\n" +
5553 "#define BINMAPSHIFT 5\n" +
5554 "#define BITSPERMAP (1U << BINMAPSHIFT)\n" +
5555 "#define BINMAPSIZE (NBINS / BITSPERMAP)\n" +
5556 "\n" +
5557 "#define idx2block(i) ((i) >> BINMAPSHIFT)\n" +
5558 "#define idx2bit(i) ((1U << ((i) & ((1U << BINMAPSHIFT)-1))))\n" +
5559 "\n" +
5560 "#define mark_bin(m,i) ((m)->binmap[idx2block(i)] |= idx2bit(i))\n" +
5561 "#define unmark_bin(m,i) ((m)->binmap[idx2block(i)] &= ~(idx2bit(i)))\n" +
5562 "#define get_binmap(m,i) ((m)->binmap[idx2block(i)] & idx2bit(i))\n" +
5563 "\n" +
5564 "/*\n" +
5565 " Fastbins\n" +
5566 "\n" +
5567 " An array of lists holding recently freed small chunks. Fastbins\n" +
5568 " are not doubly linked. It is faster to single-link them, and\n" +
5569 " since chunks are never removed from the middles of these lists,\n" +
5570 " double linking is not necessary. Also, unlike regular bins, they\n" +
5571 " are not even processed in FIFO order (they use faster LIFO) since\n" +
5572 " ordering doesn't much matter in the transient contexts in which\n" +
5573 " fastbins are normally used.\n" +
5574 "\n" +
5575 " Chunks in fastbins keep their inuse bit set, so they cannot\n" +
5576 " be consolidated with other free chunks. malloc_consolidate\n" +
5577 " releases all chunks in fastbins and consolidates them with\n" +
5578 " other free chunks.\n" +
5579 "*/\n" +
5580 "\n" +
5581 "typedef struct malloc_chunk* mfastbinptr;\n" +
5582 "\n" +
5583 "/* offset 2 to use otherwise unindexable first 2 bins */\n" +
5584 "#define fastbin_index(sz) ((((unsigned int)(sz)) >> 3) - 2)\n" +
5585 "\n" +
5586 "/* The maximum fastbin request size we support */\n" +
5587 "#define MAX_FAST_SIZE 80\n" +
5588 "\n" +
5589 "#define NFASTBINS (fastbin_index(request2size(MAX_FAST_SIZE))+1)\n" +
5590 "\n" +
5591 "/*\n" +
5592 " FASTBIN_CONSOLIDATION_THRESHOLD is the size of a chunk in free()\n" +
5593 " that triggers automatic consolidation of possibly-surrounding\n" +
5594 " fastbin chunks. This is a heuristic, so the exact value should not\n" +
5595 " matter too much. It is defined at half the default trim threshold as a\n" +
5596 " compromise heuristic to only attempt consolidation if it is likely\n" +
5597 " to lead to trimming. However, it is not dynamically tunable, since\n" +
5598 " consolidation reduces fragmentation surrounding loarge chunks even\n" +
5599 " if trimming is not used.\n" +
5600 "*/\n" +
5601 "\n" +
5602 "#define FASTBIN_CONSOLIDATION_THRESHOLD \\n" +
5603 " ((unsigned long)(DEFAULT_TRIM_THRESHOLD) >> 1)\n" +
5604 "\n" +
5605 "/*\n" +
5606 " Since the lowest 2 bits in max_fast don't matter in size comparisons,\n" +
5607 " they are used as flags.\n" +
5608 "*/\n" +
5609 "\n" +
5610 "/*\n" +
5611 " ANYCHUNKS_BIT held in max_fast indicates that there may be any\n" +
5612 " freed chunks at all. It is set true when entering a chunk into any\n" +
5613 " bin.\n" +
5614 "*/\n" +
5615 "\n" +
5616 "#define ANYCHUNKS_BIT (1U)\n" +
5617 "\n" +
5618 "#define have_anychunks(M) (((M)->max_fast & ANYCHUNKS_BIT))\n" +
5619 "#define set_anychunks(M) ((M)->max_fast |= ANYCHUNKS_BIT)\n" +
5620 "#define clear_anychunks(M) ((M)->max_fast &= ~ANYCHUNKS_BIT)\n" +
5621 "\n" +
5622 "/*\n" +
5623 " FASTCHUNKS_BIT held in max_fast indicates that there are probably\n" +
5624 " some fastbin chunks. It is set true on entering a chunk into any\n" +
5625 " fastbin, and cleared only in malloc_consolidate.\n" +
5626 "*/\n" +
5627 "\n") +
5629 "#define FASTCHUNKS_BIT (2U)\n" +
5630 "\n" +
5631 "#define have_fastchunks(M) (((M)->max_fast & FASTCHUNKS_BIT))\n" +
5632 "#define set_fastchunks(M) ((M)->max_fast |= (FASTCHUNKS_BIT|ANYCHUNKS_BIT))\n" +
5633 "#define clear_fastchunks(M) ((M)->max_fast &= ~(FASTCHUNKS_BIT))\n" +
5634 "\n" +
5635 "/*\n" +
5636 " Set value of max_fast.\n" +
5637 " Use impossibly small value if 0.\n" +
5638 "*/\n" +
5639 "\n" +
5640 "#define set_max_fast(M, s) \\n" +
5641 " (M)->max_fast = (((s) == 0)? SMALLBIN_WIDTH: request2size(s)) | \\n" +
5642 " ((M)->max_fast & (FASTCHUNKS_BIT|ANYCHUNKS_BIT))\n" +
5643 "\n" +
5644 "#define get_max_fast(M) \\n" +
5645 " ((M)->max_fast & ~(FASTCHUNKS_BIT | ANYCHUNKS_BIT))\n" +
5646 "\n" +
5647 "\n" +
5648 "/*\n" +
5649 " morecore_properties is a status word holding dynamically discovered\n" +
5650 " or controlled properties of the morecore function\n" +
5651 "*/\n" +
5652 "\n" +
5653 "#define MORECORE_CONTIGUOUS_BIT (1U)\n" +
5654 "\n" +
5655 "#define contiguous(M) \\n" +
5656 " (((M)->morecore_properties & MORECORE_CONTIGUOUS_BIT))\n" +
5657 "#define noncontiguous(M) \\n" +
5658 " (((M)->morecore_properties & MORECORE_CONTIGUOUS_BIT) == 0)\n" +
5659 "#define set_contiguous(M) \\n" +
5660 " ((M)->morecore_properties |= MORECORE_CONTIGUOUS_BIT)\n" +
5661 "#define set_noncontiguous(M) \\n" +
5662 " ((M)->morecore_properties &= ~MORECORE_CONTIGUOUS_BIT)\n" +
5663 "\n" +
5664 "\n" +
5665 "/*\n" +
5666 " ----------- Internal state representation and initialization -----------\n" +
5667 "*/\n" +
5668 "\n" +
5669 "struct malloc_state {\n" +
5670 "\n" +
5671 " /* The maximum chunk size to be eligible for fastbin */\n" +
5672 " INTERNAL_SIZE_T max_fast; /* low 2 bits used as flags */\n" +
5673 "\n" +
5674 " /* Fastbins */\n" +
5675 " mfastbinptr fastbins[NFASTBINS];\n" +
5676 "\n" +
5677 " /* Base of the topmost chunk -- not otherwise kept in a bin */\n" +
5678 " mchunkptr top;\n" +
5679 "\n" +
5680 " /* The remainder from the most recent split of a small request */\n" +
5681 " mchunkptr last_remainder;\n" +
5682 "\n" +
5683 " /* Normal bins packed as described above */\n" +
5684 " mchunkptr bins[NBINS * 2];\n" +
5685 "\n" +
5686 " /* Bitmap of bins. Trailing zero map handles cases of largest binned size */\n" +
5687 " unsigned int binmap[BINMAPSIZE+1];\n" +
5688 "\n" +
5689 " /* Tunable parameters */\n" +
5690 " CHUNK_SIZE_T trim_threshold;\n" +
5691 " INTERNAL_SIZE_T top_pad;\n" +
5692 " INTERNAL_SIZE_T mmap_threshold;\n" +
5693 "\n" +
5694 " /* Memory map support */\n" +
5695 " int n_mmaps;\n" +
5696 " int n_mmaps_max;\n" +
5697 " int max_n_mmaps;\n" +
5698 "\n" +
5699 " /* Cache malloc_getpagesize */\n" +
5700 " unsigned int pagesize;\n" +
5701 "\n" +
5702 " /* Track properties of MORECORE */\n" +
5703 " unsigned int morecore_properties;\n" +
5704 "\n" +
5705 " /* Statistics */\n" +
5706 " INTERNAL_SIZE_T mmapped_mem;\n" +
5707 " INTERNAL_SIZE_T sbrked_mem;\n" +
5708 " INTERNAL_SIZE_T max_sbrked_mem;\n" +
5709 " INTERNAL_SIZE_T max_mmapped_mem;\n" +
5710 " INTERNAL_SIZE_T max_total_mem;\n" +
5711 "};\n" +
5712 "\n" +
5713 "typedef struct malloc_state *mstate;\n" +
5714 "\n" +
5715 "/*\n" +
5716 " There is exactly one instance of this struct in this malloc.\n" +
5717 " If you are adapting this malloc in a way that does NOT use a static\n" +
5718 " malloc_state, you MUST explicitly zero-fill it before using. This\n" +
5719 " malloc relies on the property that malloc_state is initialized to\n" +
5720 " all zeroes (as is true of C statics).\n" +
5721 "*/\n" +
5722 "\n" +
5723 "static struct malloc_state av_; /* never directly referenced */\n" +
5724 "\n" +
5725 "/*\n" +
5726 " All uses of av_ are via get_malloc_state().\n" +
5727 " At most one \"call\" to get_malloc_state is made per invocation of\n" +
5728 " the public versions of malloc and free, but other routines\n" +
5729 " that in turn invoke malloc and/or free may call more then once.\n" +
5730 " Also, it is called in check* routines if DEBUG is set.\n" +
5731 "*/\n" +
5732 "\n" +
5733 "#define get_malloc_state() (&(av_))\n" +
5734 "\n" +
5735 "/*\n" +
5736 " Initialize a malloc_state struct.\n" +
5737 "\n" +
5738 " This is called only from within malloc_consolidate, which needs\n" +
5739 " be called in the same contexts anyway. It is never called directly\n" +
5740 " outside of malloc_consolidate because some optimizing compilers try\n" +
5741 " to inline it at all call points, which turns out not to be an\n" +
5742 " optimization at all. (Inlining it in malloc_consolidate is fine though.)\n" +
5743 "*/\n" +
5744 "\n" +
5745 "#if __STD_C\n" +
5746 "static void malloc_init_state(mstate av)\n" +
5747 "#else\n" +
5748 "static void malloc_init_state(av) mstate av;\n" +
5749 "#endif\n" +
5750 "{\n" +
5751 " int i;\n" +
5752 " mbinptr bin;\n" +
5753 "\n" +
5754 " /* Establish circular links for normal bins */\n" +
5755 " for (i = 1; i < NBINS; ++i) {\n" +
5756 " bin = bin_at(av,i);\n" +
5757 " bin->fd = bin->bk = bin;\n" +
5758 " }\n" +
5759 "\n" +
5760 " av->top_pad = DEFAULT_TOP_PAD;\n" +
5761 " av->n_mmaps_max = DEFAULT_MMAP_MAX;\n" +
5762 " av->mmap_threshold = DEFAULT_MMAP_THRESHOLD;\n" +
5763 " av->trim_threshold = DEFAULT_TRIM_THRESHOLD;\n" +
5764 "\n" +
5765 "#if MORECORE_CONTIGUOUS\n" +
5766 " set_contiguous(av);\n" +
5767 "#else\n" +
5768 " set_noncontiguous(av);\n" +
5769 "#endif\n" +
5770 "\n" +
5771 "\n" +
5772 " set_max_fast(av, DEFAULT_MXFAST);\n" +
5773 "\n" +
5774 " av->top = initial_top(av);\n" +
5775 " av->pagesize = malloc_getpagesize;\n" +
5776 "}\n" +
5777 "\n" +
5778 "/*\n" +
5779 " Other internal utilities operating on mstates\n" +
5780 "*/\n" +
5781 "\n") +
5783 "#if __STD_C\n" +
5784 "static Void_t* sYSMALLOc(INTERNAL_SIZE_T, mstate);\n" +
5785 "#ifndef MORECORE_CANNOT_TRIM\n" +
5786 "static int sYSTRIm(size_t, mstate);\n" +
5787 "#endif\n" +
5788 "static void malloc_consolidate(mstate);\n" +
5789 "static Void_t** iALLOc(size_t, size_t*, int, Void_t**);\n" +
5790 "#else\n" +
5791 "static Void_t* sYSMALLOc();\n" +
5792 "static int sYSTRIm();\n" +
5793 "static void malloc_consolidate();\n" +
5794 "static Void_t** iALLOc();\n" +
5795 "#endif\n" +
5796 "\n" +
5797 "/*\n" +
5798 " Debugging support\n" +
5799 "\n" +
5800 " These routines make a number of assertions about the states\n" +
5801 " of data structures that should be true at all times. If any\n" +
5802 " are not true, it's very likely that a user program has somehow\n" +
5803 " trashed memory. (It's also possible that there is a coding error\n" +
5804 " in malloc. In which case, please report it!)\n" +
5805 "*/\n" +
5806 "\n" +
5807 "#if ! DEBUG\n" +
5808 "\n" +
5809 "#define check_chunk(P)\n" +
5810 "#define check_free_chunk(P)\n" +
5811 "#define check_inuse_chunk(P)\n" +
5812 "#define check_remalloced_chunk(P,N)\n" +
5813 "#define check_malloced_chunk(P,N)\n" +
5814 "#define check_malloc_state()\n" +
5815 "\n" +
5816 "#else\n" +
5817 "#define check_chunk(P) do_check_chunk(P)\n" +
5818 "#define check_free_chunk(P) do_check_free_chunk(P)\n" +
5819 "#define check_inuse_chunk(P) do_check_inuse_chunk(P)\n" +
5820 "#define check_remalloced_chunk(P,N) do_check_remalloced_chunk(P,N)\n" +
5821 "#define check_malloced_chunk(P,N) do_check_malloced_chunk(P,N)\n" +
5822 "#define check_malloc_state() do_check_malloc_state()\n" +
5823 "\n" +
5824 "/*\n" +
5825 " Properties of all chunks\n" +
5826 "*/\n" +
5827 "\n" +
5828 "#if __STD_C\n" +
5829 "static void do_check_chunk(mchunkptr p)\n" +
5830 "#else\n" +
5831 "static void do_check_chunk(p) mchunkptr p;\n" +
5832 "#endif\n" +
5833 "{\n" +
5834 " mstate av = get_malloc_state();\n" +
5835 " CHUNK_SIZE_T sz = chunksize(p);\n" +
5836 " /* min and max possible addresses assuming contiguous allocation */\n" +
5837 " char* max_address = (char*)(av->top) + chunksize(av->top);\n" +
5838 " char* min_address = max_address - av->sbrked_mem;\n" +
5839 "\n" +
5840 " if (!chunk_is_mmapped(p)) {\n" +
5841 "\n" +
5842 " /* Has legal address ... */\n" +
5843 " if (p != av->top) {\n" +
5844 " if (contiguous(av)) {\n" +
5845 " assert(((char*)p) >= min_address);\n" +
5846 " assert(((char*)p + sz) <= ((char*)(av->top)));\n" +
5847 " }\n" +
5848 " }\n" +
5849 " else {\n" +
5850 " /* top size is always at least MINSIZE */\n" +
5851 " assert((CHUNK_SIZE_T)(sz) >= MINSIZE);\n" +
5852 " /* top predecessor always marked inuse */\n" +
5853 " assert(prev_inuse(p));\n" +
5854 " }\n" +
5855 "\n" +
5856 " }\n" +
5857 " else {\n" +
5858 "#if HAVE_MMAP\n" +
5859 " /* address is outside main heap */\n" +
5860 " if (contiguous(av) && av->top != initial_top(av)) {\n" +
5861 " assert(((char*)p) < min_address || ((char*)p) > max_address);\n" +
5862 " }\n" +
5863 " /* chunk is page-aligned */\n" +
5864 " assert(((p->prev_size + sz) & (av->pagesize-1)) == 0);\n" +
5865 " /* mem is aligned */\n" +
5866 " assert(aligned_OK(chunk2mem(p)));\n" +
5867 "#else\n" +
5868 " /* force an appropriate assert violation if debug set */\n" +
5869 " assert(!chunk_is_mmapped(p));\n" +
5870 "#endif\n" +
5871 " }\n" +
5872 "}\n" +
5873 "\n" +
5874 "/*\n" +
5875 " Properties of free chunks\n" +
5876 "*/\n" +
5877 "\n" +
5878 "#if __STD_C\n" +
5879 "static void do_check_free_chunk(mchunkptr p)\n" +
5880 "#else\n" +
5881 "static void do_check_free_chunk(p) mchunkptr p;\n" +
5882 "#endif\n" +
5883 "{\n" +
5884 " mstate av = get_malloc_state();\n" +
5885 "\n" +
5886 " INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE;\n" +
5887 " mchunkptr next = chunk_at_offset(p, sz);\n" +
5888 "\n" +
5889 " do_check_chunk(p);\n" +
5890 "\n" +
5891 " /* Chunk must claim to be free ... */\n" +
5892 " assert(!inuse(p));\n" +
5893 " assert (!chunk_is_mmapped(p));\n" +
5894 "\n" +
5895 " /* Unless a special marker, must have OK fields */\n" +
5896 " if ((CHUNK_SIZE_T)(sz) >= MINSIZE)\n" +
5897 " {\n" +
5898 " assert((sz & MALLOC_ALIGN_MASK) == 0);\n" +
5899 " assert(aligned_OK(chunk2mem(p)));\n" +
5900 " /* ... matching footer field */\n" +
5901 " assert(next->prev_size == sz);\n" +
5902 " /* ... and is fully consolidated */\n" +
5903 " assert(prev_inuse(p));\n" +
5904 " assert (next == av->top || inuse(next));\n" +
5905 "\n" +
5906 " /* ... and has minimally sane links */\n" +
5907 " assert(p->fd->bk == p);\n" +
5908 " assert(p->bk->fd == p);\n" +
5909 " }\n" +
5910 " else /* markers are always of size SIZE_SZ */\n" +
5911 " assert(sz == SIZE_SZ);\n" +
5912 "}\n" +
5913 "\n" +
5914 "/*\n" +
5915 " Properties of inuse chunks\n" +
5916 "*/\n" +
5917 "\n" +
5918 "#if __STD_C\n" +
5919 "static void do_check_inuse_chunk(mchunkptr p)\n" +
5920 "#else\n" +
5921 "static void do_check_inuse_chunk(p) mchunkptr p;\n" +
5922 "#endif\n" +
5923 "{\n" +
5924 " mstate av = get_malloc_state();\n" +
5925 " mchunkptr next;\n" +
5926 " do_check_chunk(p);\n" +
5927 "\n" +
5928 " if (chunk_is_mmapped(p))\n" +
5929 " return; /* mmapped chunks have no next/prev */\n" +
5930 "\n" +
5931 " /* Check whether it claims to be in use ... */\n" +
5932 " assert(inuse(p));\n" +
5933 "\n") +
5935 " next = next_chunk(p);\n" +
5936 "\n" +
5937 " /* ... and is surrounded by OK chunks.\n" +
5938 " Since more things can be checked with free chunks than inuse ones,\n" +
5939 " if an inuse chunk borders them and debug is on, it's worth doing them.\n" +
5940 " */\n" +
5941 " if (!prev_inuse(p)) {\n" +
5942 " /* Note that we cannot even look at prev unless it is not inuse */\n" +
5943 " mchunkptr prv = prev_chunk(p);\n" +
5944 " assert(next_chunk(prv) == p);\n" +
5945 " do_check_free_chunk(prv);\n" +
5946 " }\n" +
5947 "\n" +
5948 " if (next == av->top) {\n" +
5949 " assert(prev_inuse(next));\n" +
5950 " assert(chunksize(next) >= MINSIZE);\n" +
5951 " }\n" +
5952 " else if (!inuse(next))\n" +
5953 " do_check_free_chunk(next);\n" +
5954 "}\n" +
5955 "\n" +
5956 "/*\n" +
5957 " Properties of chunks recycled from fastbins\n" +
5958 "*/\n" +
5959 "\n" +
5960 "#if __STD_C\n" +
5961 "static void do_check_remalloced_chunk(mchunkptr p, INTERNAL_SIZE_T s)\n" +
5962 "#else\n" +
5963 "static void do_check_remalloced_chunk(p, s) mchunkptr p; INTERNAL_SIZE_T s;\n" +
5964 "#endif\n" +
5965 "{\n" +
5966 " INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE;\n" +
5967 "\n" +
5968 " do_check_inuse_chunk(p);\n" +
5969 "\n" +
5970 " /* Legal size ... */\n" +
5971 " assert((sz & MALLOC_ALIGN_MASK) == 0);\n" +
5972 " assert((CHUNK_SIZE_T)(sz) >= MINSIZE);\n" +
5973 " /* ... and alignment */\n" +
5974 " assert(aligned_OK(chunk2mem(p)));\n" +
5975 " /* chunk is less than MINSIZE more than request */\n" +
5976 " assert((long)(sz) - (long)(s) >= 0);\n" +
5977 " assert((long)(sz) - (long)(s + MINSIZE) < 0);\n" +
5978 "}\n" +
5979 "\n" +
5980 "/*\n" +
5981 " Properties of nonrecycled chunks at the point they are malloced\n" +
5982 "*/\n" +
5983 "\n" +
5984 "#if __STD_C\n" +
5985 "static void do_check_malloced_chunk(mchunkptr p, INTERNAL_SIZE_T s)\n" +
5986 "#else\n" +
5987 "static void do_check_malloced_chunk(p, s) mchunkptr p; INTERNAL_SIZE_T s;\n" +
5988 "#endif\n" +
5989 "{\n" +
5990 " /* same as recycled case ... */\n" +
5991 " do_check_remalloced_chunk(p, s);\n" +
5992 "\n" +
5993 " /*\n" +
5994 " ... plus, must obey implementation invariant that prev_inuse is\n" +
5995 " always true of any allocated chunk; i.e., that each allocated\n" +
5996 " chunk borders either a previously allocated and still in-use\n" +
5997 " chunk, or the base of its memory arena. This is ensured\n" +
5998 " by making all allocations from the the `lowest' part of any found\n" +
5999 " chunk. This does not necessarily hold however for chunks\n" +
6000 " recycled via fastbins.\n" +
6001 " */\n" +
6002 "\n" +
6003 " assert(prev_inuse(p));\n" +
6004 "}\n" +
6005 "\n" +
6006 "\n" +
6007 "/*\n" +
6008 " Properties of malloc_state.\n" +
6009 "\n" +
6010 " This may be useful for debugging malloc, as well as detecting user\n" +
6011 " programmer errors that somehow write into malloc_state.\n" +
6012 "\n" +
6013 " If you are extending or experimenting with this malloc, you can\n" +
6014 " probably figure out how to hack this routine to print out or\n" +
6015 " display chunk addresses, sizes, bins, and other instrumentation.\n" +
6016 "*/\n" +
6017 "\n" +
6018 "static void do_check_malloc_state()\n" +
6019 "{\n" +
6020 " mstate av = get_malloc_state();\n" +
6021 " unsigned int i;\n" +
6022 " mchunkptr p;\n" +
6023 " mchunkptr q;\n" +
6024 " mbinptr b;\n" +
6025 " unsigned int binbit;\n" +
6026 " int empty;\n" +
6027 " unsigned int idx;\n" +
6028 " INTERNAL_SIZE_T size;\n" +
6029 " CHUNK_SIZE_T total = 0;\n" +
6030 " int max_fast_bin;\n" +
6031 "\n" +
6032 " /* internal size_t must be no wider than pointer type */\n" +
6033 " assert(sizeof(INTERNAL_SIZE_T) <= sizeof(char*));\n" +
6034 "\n" +
6035 " /* alignment is a power of 2 */\n" +
6036 " assert((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT-1)) == 0);\n" +
6037 "\n" +
6038 " /* cannot run remaining checks until fully initialized */\n" +
6039 " if (av->top == 0 || av->top == initial_top(av))\n" +
6040 " return;\n" +
6041 "\n" +
6042 " /* pagesize is a power of 2 */\n" +
6043 " assert((av->pagesize & (av->pagesize-1)) == 0);\n" +
6044 "\n" +
6045 " /* properties of fastbins */\n" +
6046 "\n" +
6047 " /* max_fast is in allowed range */\n" +
6048 " assert(get_max_fast(av) <= request2size(MAX_FAST_SIZE));\n" +
6049 "\n" +
6050 " max_fast_bin = fastbin_index(av->max_fast);\n" +
6051 "\n" +
6052 " for (i = 0; i < NFASTBINS; ++i) {\n" +
6053 " p = av->fastbins[i];\n" +
6054 "\n" +
6055 " /* all bins past max_fast are empty */\n" +
6056 " if (i > max_fast_bin)\n" +
6057 " assert(p == 0);\n" +
6058 "\n" +
6059 " while (p != 0) {\n" +
6060 " /* each chunk claims to be inuse */\n" +
6061 " do_check_inuse_chunk(p);\n" +
6062 " total += chunksize(p);\n" +
6063 " /* chunk belongs in this bin */\n" +
6064 " assert(fastbin_index(chunksize(p)) == i);\n" +
6065 " p = p->fd;\n" +
6066 " }\n" +
6067 " }\n" +
6068 "\n" +
6069 " if (total != 0)\n" +
6070 " assert(have_fastchunks(av));\n" +
6071 " else if (!have_fastchunks(av))\n" +
6072 " assert(total == 0);\n" +
6073 "\n" +
6074 " /* check normal bins */\n" +
6075 " for (i = 1; i < NBINS; ++i) {\n" +
6076 " b = bin_at(av,i);\n" +
6077 "\n" +
6078 " /* binmap is accurate (except for bin 1 == unsorted_chunks) */\n" +
6079 " if (i >= 2) {\n" +
6080 " binbit = get_binmap(av,i);\n" +
6081 " empty = last(b) == b;\n" +
6082 " if (!binbit)\n" +
6083 " assert(empty);\n" +
6084 " else if (!empty)\n" +
6085 " assert(binbit);\n" +
6086 " }\n" +
6087 "\n") +
6089 " for (p = last(b); p != b; p = p->bk) {\n" +
6090 " /* each chunk claims to be free */\n" +
6091 " do_check_free_chunk(p);\n" +
6092 " size = chunksize(p);\n" +
6093 " total += size;\n" +
6094 " if (i >= 2) {\n" +
6095 " /* chunk belongs in bin */\n" +
6096 " idx = bin_index(size);\n" +
6097 " assert(idx == i);\n" +
6098 " /* lists are sorted */\n" +
6099 " if ((CHUNK_SIZE_T) size >= (CHUNK_SIZE_T)(FIRST_SORTED_BIN_SIZE)) {\n" +
6100 " assert(p->bk == b ||\n" +
6101 " (CHUNK_SIZE_T)chunksize(p->bk) >=\n" +
6102 " (CHUNK_SIZE_T)chunksize(p));\n" +
6103 " }\n" +
6104 " }\n" +
6105 " /* chunk is followed by a legal chain of inuse chunks */\n" +
6106 " for (q = next_chunk(p);\n" +
6107 " (q != av->top && inuse(q) &&\n" +
6108 " (CHUNK_SIZE_T)(chunksize(q)) >= MINSIZE);\n" +
6109 " q = next_chunk(q))\n" +
6110 " do_check_inuse_chunk(q);\n" +
6111 " }\n" +
6112 " }\n" +
6113 "\n" +
6114 " /* top chunk is OK */\n" +
6115 " check_chunk(av->top);\n" +
6116 "\n" +
6117 " /* sanity checks for statistics */\n" +
6118 "\n" +
6119 " assert(total <= (CHUNK_SIZE_T)(av->max_total_mem));\n" +
6120 " assert(av->n_mmaps >= 0);\n" +
6121 " assert(av->n_mmaps <= av->max_n_mmaps);\n" +
6122 "\n" +
6123 " assert((CHUNK_SIZE_T)(av->sbrked_mem) <=\n" +
6124 " (CHUNK_SIZE_T)(av->max_sbrked_mem));\n" +
6125 "\n" +
6126 " assert((CHUNK_SIZE_T)(av->mmapped_mem) <=\n" +
6127 " (CHUNK_SIZE_T)(av->max_mmapped_mem));\n" +
6128 "\n" +
6129 " assert((CHUNK_SIZE_T)(av->max_total_mem) >=\n" +
6130 " (CHUNK_SIZE_T)(av->mmapped_mem) + (CHUNK_SIZE_T)(av->sbrked_mem));\n" +
6131 "}\n" +
6132 "#endif\n" +
6133 "\n" +
6134 "\n" +
6135 "/* ----------- Routines dealing with system allocation -------------- */\n" +
6136 "\n" +
6137 "/*\n" +
6138 " sysmalloc handles malloc cases requiring more memory from the system.\n" +
6139 " On entry, it is assumed that av->top does not have enough\n" +
6140 " space to service request for nb bytes, thus requiring that av->top\n" +
6141 " be extended or replaced.\n" +
6142 "*/\n" +
6143 "\n" +
6144 "#if __STD_C\n" +
6145 "static Void_t* sYSMALLOc(INTERNAL_SIZE_T nb, mstate av)\n" +
6146 "#else\n" +
6147 "static Void_t* sYSMALLOc(nb, av) INTERNAL_SIZE_T nb; mstate av;\n" +
6148 "#endif\n" +
6149 "{\n" +
6150 " mchunkptr old_top; /* incoming value of av->top */\n" +
6151 " INTERNAL_SIZE_T old_size; /* its size */\n" +
6152 " char* old_end; /* its end address */\n" +
6153 "\n" +
6154 " long size; /* arg to first MORECORE or mmap call */\n" +
6155 " char* brk; /* return value from MORECORE */\n" +
6156 "\n" +
6157 " long correction; /* arg to 2nd MORECORE call */\n" +
6158 " char* snd_brk; /* 2nd return val */\n" +
6159 "\n" +
6160 " INTERNAL_SIZE_T front_misalign; /* unusable bytes at front of new space */\n" +
6161 " INTERNAL_SIZE_T end_misalign; /* partial page left at end of new space */\n" +
6162 " char* aligned_brk; /* aligned offset into brk */\n" +
6163 "\n" +
6164 " mchunkptr p; /* the allocated/returned chunk */\n" +
6165 " mchunkptr remainder; /* remainder from allocation */\n" +
6166 " CHUNK_SIZE_T remainder_size; /* its size */\n" +
6167 "\n" +
6168 " CHUNK_SIZE_T sum; /* for updating stats */\n" +
6169 "\n" +
6170 " size_t pagemask = av->pagesize - 1;\n" +
6171 "\n" +
6172 " /*\n" +
6173 " If there is space available in fastbins, consolidate and retry\n" +
6174 " malloc from scratch rather than getting memory from system. This\n" +
6175 " can occur only if nb is in smallbin range so we didn't consolidate\n" +
6176 " upon entry to malloc. It is much easier to handle this case here\n" +
6177 " than in malloc proper.\n" +
6178 " */\n" +
6179 "\n" +
6180 " if (have_fastchunks(av)) {\n" +
6181 " assert(in_smallbin_range(nb));\n" +
6182 " malloc_consolidate(av);\n" +
6183 " return mALLOc(nb - MALLOC_ALIGN_MASK);\n" +
6184 " }\n" +
6185 "\n" +
6186 "\n" +
6187 "#if HAVE_MMAP\n" +
6188 "\n" +
6189 " /*\n" +
6190 " If have mmap, and the request size meets the mmap threshold, and\n" +
6191 " the system supports mmap, and there are few enough currently\n" +
6192 " allocated mmapped regions, try to directly map this request\n" +
6193 " rather than expanding top.\n" +
6194 " */\n" +
6195 "\n" +
6196 " if ((CHUNK_SIZE_T)(nb) >= (CHUNK_SIZE_T)(av->mmap_threshold) &&\n" +
6197 " (av->n_mmaps < av->n_mmaps_max)) {\n" +
6198 "\n" +
6199 " char* mm; /* return value from mmap call*/\n" +
6200 "\n" +
6201 " /*\n" +
6202 " Round up size to nearest page. For mmapped chunks, the overhead\n" +
6203 " is one SIZE_SZ unit larger than for normal chunks, because there\n" +
6204 " is no following chunk whose prev_size field could be used.\n" +
6205 " */\n" +
6206 " size = (nb + SIZE_SZ + MALLOC_ALIGN_MASK + pagemask) & ~pagemask;\n" +
6207 "\n" +
6208 " /* Don't try if size wraps around 0 */\n" +
6209 " if ((CHUNK_SIZE_T)(size) > (CHUNK_SIZE_T)(nb)) {\n" +
6210 "\n" +
6211 " mm = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE));\n" +
6212 "\n" +
6213 " if (mm != (char*)(MORECORE_FAILURE)) {\n" +
6214 "\n" +
6215 " /*\n" +
6216 " The offset to the start of the mmapped region is stored\n" +
6217 " in the prev_size field of the chunk. This allows us to adjust\n" +
6218 " returned start address to meet alignment requirements here\n" +
6219 " and in memalign(), and still be able to compute proper\n" +
6220 " address argument for later munmap in free() and realloc().\n" +
6221 " */\n" +
6222 "\n" +
6223 " front_misalign = (INTERNAL_SIZE_T)chunk2mem(mm) & MALLOC_ALIGN_MASK;\n" +
6224 " if (front_misalign > 0) {\n" +
6225 " correction = MALLOC_ALIGNMENT - front_misalign;\n" +
6226 " p = (mchunkptr)(mm + correction);\n" +
6227 " p->prev_size = correction;\n" +
6228 " set_head(p, (size - correction) |IS_MMAPPED);\n" +
6229 " }\n" +
6230 " else {\n" +
6231 " p = (mchunkptr)mm;\n" +
6232 " p->prev_size = 0;\n" +
6233 " set_head(p, size|IS_MMAPPED);\n" +
6234 " }\n" +
6235 "\n" +
6236 " /* update statistics */\n" +
6237 "\n" +
6238 " if (++av->n_mmaps > av->max_n_mmaps)\n" +
6239 " av->max_n_mmaps = av->n_mmaps;\n" +
6240 "\n") +
6242 " sum = av->mmapped_mem += size;\n" +
6243 " if (sum > (CHUNK_SIZE_T)(av->max_mmapped_mem))\n" +
6244 " av->max_mmapped_mem = sum;\n" +
6245 " sum += av->sbrked_mem;\n" +
6246 " if (sum > (CHUNK_SIZE_T)(av->max_total_mem))\n" +
6247 " av->max_total_mem = sum;\n" +
6248 "\n" +
6249 " check_chunk(p);\n" +
6250 "\n" +
6251 " return chunk2mem(p);\n" +
6252 " }\n" +
6253 " }\n" +
6254 " }\n" +
6255 "#endif\n" +
6256 "\n" +
6257 " /* Record incoming configuration of top */\n" +
6258 "\n" +
6259 " old_top = av->top;\n" +
6260 " old_size = chunksize(old_top);\n" +
6261 " old_end = (char*)(chunk_at_offset(old_top, old_size));\n" +
6262 "\n" +
6263 " brk = snd_brk = (char*)(MORECORE_FAILURE);\n" +
6264 "\n" +
6265 " /*\n" +
6266 " If not the first time through, we require old_size to be\n" +
6267 " at least MINSIZE and to have prev_inuse set.\n" +
6268 " */\n" +
6269 "\n" +
6270 " assert((old_top == initial_top(av) && old_size == 0) ||\n" +
6271 " ((CHUNK_SIZE_T) (old_size) >= MINSIZE &&\n" +
6272 " prev_inuse(old_top)));\n" +
6273 "\n" +
6274 " /* Precondition: not enough current space to satisfy nb request */\n" +
6275 " assert((CHUNK_SIZE_T)(old_size) < (CHUNK_SIZE_T)(nb + MINSIZE));\n" +
6276 "\n" +
6277 " /* Precondition: all fastbins are consolidated */\n" +
6278 " assert(!have_fastchunks(av));\n" +
6279 "\n" +
6280 "\n" +
6281 " /* Request enough space for nb + pad + overhead */\n" +
6282 "\n" +
6283 " size = nb + av->top_pad + MINSIZE;\n" +
6284 "\n" +
6285 " /*\n" +
6286 " If contiguous, we can subtract out existing space that we hope to\n" +
6287 " combine with new space. We add it back later only if\n" +
6288 " we don't actually get contiguous space.\n" +
6289 " */\n" +
6290 "\n" +
6291 " if (contiguous(av))\n" +
6292 " size -= old_size;\n" +
6293 "\n" +
6294 " /*\n" +
6295 " Round to a multiple of page size.\n" +
6296 " If MORECORE is not contiguous, this ensures that we only call it\n" +
6297 " with whole-page arguments. And if MORECORE is contiguous and\n" +
6298 " this is not first time through, this preserves page-alignment of\n" +
6299 " previous calls. Otherwise, we correct to page-align below.\n" +
6300 " */\n" +
6301 "\n" +
6302 " size = (size + pagemask) & ~pagemask;\n" +
6303 "\n" +
6304 " /*\n" +
6305 " Don't try to call MORECORE if argument is so big as to appear\n" +
6306 " negative. Note that since mmap takes size_t arg, it may succeed\n" +
6307 " below even if we cannot call MORECORE.\n" +
6308 " */\n" +
6309 "\n" +
6310 " if (size > 0)\n" +
6311 " brk = (char*)(MORECORE(size));\n" +
6312 "\n" +
6313 " /*\n" +
6314 " If have mmap, try using it as a backup when MORECORE fails or\n" +
6315 " cannot be used. This is worth doing on systems that have \"holes\" in\n" +
6316 " address space, so sbrk cannot extend to give contiguous space, but\n" +
6317 " space is available elsewhere. Note that we ignore mmap max count\n" +
6318 " and threshold limits, since the space will not be used as a\n" +
6319 " segregated mmap region.\n" +
6320 " */\n" +
6321 "\n" +
6322 "#if HAVE_MMAP\n" +
6323 " if (brk == (char*)(MORECORE_FAILURE)) {\n" +
6324 "\n" +
6325 " /* Cannot merge with old top, so add its size back in */\n" +
6326 " if (contiguous(av))\n" +
6327 " size = (size + old_size + pagemask) & ~pagemask;\n" +
6328 "\n" +
6329 " /* If we are relying on mmap as backup, then use larger units */\n" +
6330 " if ((CHUNK_SIZE_T)(size) < (CHUNK_SIZE_T)(MMAP_AS_MORECORE_SIZE))\n" +
6331 " size = MMAP_AS_MORECORE_SIZE;\n" +
6332 "\n" +
6333 " /* Don't try if size wraps around 0 */\n" +
6334 " if ((CHUNK_SIZE_T)(size) > (CHUNK_SIZE_T)(nb)) {\n" +
6335 "\n" +
6336 " brk = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE));\n" +
6337 "\n" +
6338 " if (brk != (char*)(MORECORE_FAILURE)) {\n" +
6339 "\n" +
6340 " /* We do not need, and cannot use, another sbrk call to find end */\n" +
6341 " snd_brk = brk + size;\n" +
6342 "\n" +
6343 " /*\n" +
6344 " Record that we no longer have a contiguous sbrk region.\n" +
6345 " After the first time mmap is used as backup, we do not\n" +
6346 " ever rely on contiguous space since this could incorrectly\n" +
6347 " bridge regions.\n" +
6348 " */\n" +
6349 " set_noncontiguous(av);\n" +
6350 " }\n" +
6351 " }\n" +
6352 " }\n" +
6353 "#endif\n" +
6354 "\n" +
6355 " if (brk != (char*)(MORECORE_FAILURE)) {\n" +
6356 " av->sbrked_mem += size;\n" +
6357 "\n" +
6358 " /*\n" +
6359 " If MORECORE extends previous space, we can likewise extend top size.\n" +
6360 " */\n" +
6361 "\n" +
6362 " if (brk == old_end && snd_brk == (char*)(MORECORE_FAILURE)) {\n" +
6363 " set_head(old_top, (size + old_size) | PREV_INUSE);\n" +
6364 " }\n" +
6365 "\n" +
6366 " /*\n" +
6367 " Otherwise, make adjustments:\n" +
6368 "\n" +
6369 " * If the first time through or noncontiguous, we need to call sbrk\n" +
6370 " just to find out where the end of memory lies.\n" +
6371 "\n" +
6372 " * We need to ensure that all returned chunks from malloc will meet\n" +
6373 " MALLOC_ALIGNMENT\n" +
6374 "\n" +
6375 " * If there was an intervening foreign sbrk, we need to adjust sbrk\n" +
6376 " request size to account for fact that we will not be able to\n" +
6377 " combine new space with existing space in old_top.\n" +
6378 "\n" +
6379 " * Almost all systems internally allocate whole pages at a time, in\n" +
6380 " which case we might as well use the whole last page of request.\n" +
6381 " So we allocate enough more memory to hit a page boundary now,\n" +
6382 " which in turn causes future contiguous calls to page-align.\n" +
6383 " */\n" +
6384 "\n" +
6385 " else {\n" +
6386 " front_misalign = 0;\n" +
6387 " end_misalign = 0;\n" +
6388 " correction = 0;\n" +
6389 " aligned_brk = brk;\n" +
6390 "\n") +
6392 " /*\n" +
6393 " If MORECORE returns an address lower than we have seen before,\n" +
6394 " we know it isn't really contiguous. This and some subsequent\n" +
6395 " checks help cope with non-conforming MORECORE functions and\n" +
6396 " the presence of \"foreign\" calls to MORECORE from outside of\n" +
6397 " malloc or by other threads. We cannot guarantee to detect\n" +
6398 " these in all cases, but cope with the ones we do detect.\n" +
6399 " */\n" +
6400 " if (contiguous(av) && old_size != 0 && brk < old_end) {\n" +
6401 " set_noncontiguous(av);\n" +
6402 " }\n" +
6403 "\n" +
6404 " /* handle contiguous cases */\n" +
6405 " if (contiguous(av)) {\n" +
6406 "\n" +
6407 " /*\n" +
6408 " We can tolerate forward non-contiguities here (usually due\n" +
6409 " to foreign calls) but treat them as part of our space for\n" +
6410 " stats reporting.\n" +
6411 " */\n" +
6412 " if (old_size != 0)\n" +
6413 " av->sbrked_mem += brk - old_end;\n" +
6414 "\n" +
6415 " /* Guarantee alignment of first new chunk made from this space */\n" +
6416 "\n" +
6417 " front_misalign = (INTERNAL_SIZE_T)chunk2mem(brk) & MALLOC_ALIGN_MASK;\n" +
6418 " if (front_misalign > 0) {\n" +
6419 "\n" +
6420 " /*\n" +
6421 " Skip over some bytes to arrive at an aligned position.\n" +
6422 " We don't need to specially mark these wasted front bytes.\n" +
6423 " They will never be accessed anyway because\n" +
6424 " prev_inuse of av->top (and any chunk created from its start)\n" +
6425 " is always true after initialization.\n" +
6426 " */\n" +
6427 "\n" +
6428 " correction = MALLOC_ALIGNMENT - front_misalign;\n" +
6429 " aligned_brk += correction;\n" +
6430 " }\n" +
6431 "\n" +
6432 " /*\n" +
6433 " If this isn't adjacent to existing space, then we will not\n" +
6434 " be able to merge with old_top space, so must add to 2nd request.\n" +
6435 " */\n" +
6436 "\n" +
6437 " correction += old_size;\n" +
6438 "\n" +
6439 " /* Extend the end address to hit a page boundary */\n" +
6440 " end_misalign = (INTERNAL_SIZE_T)(brk + size + correction);\n" +
6441 " correction += ((end_misalign + pagemask) & ~pagemask) - end_misalign;\n" +
6442 "\n" +
6443 " assert(correction >= 0);\n" +
6444 " snd_brk = (char*)(MORECORE(correction));\n" +
6445 "\n" +
6446 " if (snd_brk == (char*)(MORECORE_FAILURE)) {\n" +
6447 " /*\n" +
6448 " If can't allocate correction, try to at least find out current\n" +
6449 " brk. It might be enough to proceed without failing.\n" +
6450 " */\n" +
6451 " correction = 0;\n" +
6452 " snd_brk = (char*)(MORECORE(0));\n" +
6453 " }\n" +
6454 " else if (snd_brk < brk) {\n" +
6455 " /*\n" +
6456 " If the second call gives noncontiguous space even though\n" +
6457 " it says it won't, the only course of action is to ignore\n" +
6458 " results of second call, and conservatively estimate where\n" +
6459 " the first call left us. Also set noncontiguous, so this\n" +
6460 " won't happen again, leaving at most one hole.\n" +
6461 "\n" +
6462 " Note that this check is intrinsically incomplete. Because\n" +
6463 " MORECORE is allowed to give more space than we ask for,\n" +
6464 " there is no reliable way to detect a noncontiguity\n" +
6465 " producing a forward gap for the second call.\n" +
6466 " */\n" +
6467 " snd_brk = brk + size;\n" +
6468 " correction = 0;\n" +
6469 " set_noncontiguous(av);\n" +
6470 " }\n" +
6471 "\n" +
6472 " }\n" +
6473 "\n" +
6474 " /* handle non-contiguous cases */\n" +
6475 " else {\n" +
6476 " /* MORECORE/mmap must correctly align */\n" +
6477 " assert(aligned_OK(chunk2mem(brk)));\n" +
6478 "\n" +
6479 " /* Find out current end of memory */\n" +
6480 " if (snd_brk == (char*)(MORECORE_FAILURE)) {\n" +
6481 " snd_brk = (char*)(MORECORE(0));\n" +
6482 " av->sbrked_mem += snd_brk - brk - size;\n" +
6483 " }\n" +
6484 " }\n" +
6485 "\n" +
6486 " /* Adjust top based on results of second sbrk */\n" +
6487 " if (snd_brk != (char*)(MORECORE_FAILURE)) {\n" +
6488 " av->top = (mchunkptr)aligned_brk;\n" +
6489 " set_head(av->top, (snd_brk - aligned_brk + correction) | PREV_INUSE);\n" +
6490 " av->sbrked_mem += correction;\n" +
6491 "\n" +
6492 " /*\n" +
6493 " If not the first time through, we either have a\n" +
6494 " gap due to foreign sbrk or a non-contiguous region. Insert a\n" +
6495 " double fencepost at old_top to prevent consolidation with space\n" +
6496 " we don't own. These fenceposts are artificial chunks that are\n" +
6497 " marked as inuse and are in any case too small to use. We need\n" +
6498 " two to make sizes and alignments work out.\n" +
6499 " */\n" +
6500 "\n" +
6501 " if (old_size != 0) {\n" +
6502 " /*\n" +
6503 " Shrink old_top to insert fenceposts, keeping size a\n" +
6504 " multiple of MALLOC_ALIGNMENT. We know there is at least\n" +
6505 " enough space in old_top to do this.\n" +
6506 " */\n" +
6507 " old_size = (old_size - 3*SIZE_SZ) & ~MALLOC_ALIGN_MASK;\n" +
6508 " set_head(old_top, old_size | PREV_INUSE);\n" +
6509 "\n" +
6510 " /*\n" +
6511 " Note that the following assignments completely overwrite\n" +
6512 " old_top when old_size was previously MINSIZE. This is\n" +
6513 " intentional. We need the fencepost, even if old_top otherwise gets\n" +
6514 " lost.\n" +
6515 " */\n" +
6516 " chunk_at_offset(old_top, old_size )->size =\n" +
6517 " SIZE_SZ|PREV_INUSE;\n" +
6518 "\n" +
6519 " chunk_at_offset(old_top, old_size + SIZE_SZ)->size =\n" +
6520 " SIZE_SZ|PREV_INUSE;\n" +
6521 "\n" +
6522 " /*\n" +
6523 " If possible, release the rest, suppressing trimming.\n" +
6524 " */\n" +
6525 " if (old_size >= MINSIZE) {\n" +
6526 " INTERNAL_SIZE_T tt = av->trim_threshold;\n" +
6527 " av->trim_threshold = (INTERNAL_SIZE_T)(-1);\n" +
6528 " fREe(chunk2mem(old_top));\n" +
6529 " av->trim_threshold = tt;\n" +
6530 " }\n" +
6531 " }\n" +
6532 " }\n" +
6533 " }\n" +
6534 "\n" +
6535 " /* Update statistics */\n" +
6536 " sum = av->sbrked_mem;\n" +
6537 " if (sum > (CHUNK_SIZE_T)(av->max_sbrked_mem))\n" +
6538 " av->max_sbrked_mem = sum;\n" +
6539 "\n") +
6541 " sum += av->mmapped_mem;\n" +
6542 " if (sum > (CHUNK_SIZE_T)(av->max_total_mem))\n" +
6543 " av->max_total_mem = sum;\n" +
6544 "\n" +
6545 " check_malloc_state();\n" +
6546 "\n" +
6547 " /* finally, do the allocation */\n" +
6548 "\n" +
6549 " p = av->top;\n" +
6550 " size = chunksize(p);\n" +
6551 "\n" +
6552 " /* check that one of the above allocation paths succeeded */\n" +
6553 " if ((CHUNK_SIZE_T)(size) >= (CHUNK_SIZE_T)(nb + MINSIZE)) {\n" +
6554 " remainder_size = size - nb;\n" +
6555 " remainder = chunk_at_offset(p, nb);\n" +
6556 " av->top = remainder;\n" +
6557 " set_head(p, nb | PREV_INUSE);\n" +
6558 " set_head(remainder, remainder_size | PREV_INUSE);\n" +
6559 " check_malloced_chunk(p, nb);\n" +
6560 " return chunk2mem(p);\n" +
6561 " }\n" +
6562 "\n" +
6563 " }\n" +
6564 "\n" +
6565 " /* catch all failure paths */\n" +
6566 " MALLOC_FAILURE_ACTION;\n" +
6567 " return 0;\n" +
6568 "}\n" +
6569 "\n" +
6570 "\n" +
6571 "\n" +
6572 "\n" +
6573 "/*\n" +
6574 " sYSTRIm is an inverse of sorts to sYSMALLOc. It gives memory back\n" +
6575 " to the system (via negative arguments to sbrk) if there is unused\n" +
6576 " memory at the `high' end of the malloc pool. It is called\n" +
6577 " automatically by free() when top space exceeds the trim\n" +
6578 " threshold. It is also called by the public malloc_trim routine. It\n" +
6579 " returns 1 if it actually released any memory, else 0.\n" +
6580 "*/\n" +
6581 "\n" +
6582 "#ifndef MORECORE_CANNOT_TRIM\n" +
6583 "\n" +
6584 "#if __STD_C\n" +
6585 "static int sYSTRIm(size_t pad, mstate av)\n" +
6586 "#else\n" +
6587 "static int sYSTRIm(pad, av) size_t pad; mstate av;\n" +
6588 "#endif\n" +
6589 "{\n" +
6590 " long top_size; /* Amount of top-most memory */\n" +
6591 " long extra; /* Amount to release */\n" +
6592 " long released; /* Amount actually released */\n" +
6593 " char* current_brk; /* address returned by pre-check sbrk call */\n" +
6594 " char* new_brk; /* address returned by post-check sbrk call */\n" +
6595 " size_t pagesz;\n" +
6596 "\n" +
6597 " pagesz = av->pagesize;\n" +
6598 " top_size = chunksize(av->top);\n" +
6599 "\n" +
6600 " /* Release in pagesize units, keeping at least one page */\n" +
6601 " extra = ((top_size - pad - MINSIZE + (pagesz-1)) / pagesz - 1) * pagesz;\n" +
6602 "\n" +
6603 " if (extra > 0) {\n" +
6604 "\n" +
6605 " /*\n" +
6606 " Only proceed if end of memory is where we last set it.\n" +
6607 " This avoids problems if there were foreign sbrk calls.\n" +
6608 " */\n" +
6609 " current_brk = (char*)(MORECORE(0));\n" +
6610 " if (current_brk == (char*)(av->top) + top_size) {\n" +
6611 "\n" +
6612 " /*\n" +
6613 " Attempt to release memory. We ignore MORECORE return value,\n" +
6614 " and instead call again to find out where new end of memory is.\n" +
6615 " This avoids problems if first call releases less than we asked,\n" +
6616 " of if failure somehow altered brk value. (We could still\n" +
6617 " encounter problems if it altered brk in some very bad way,\n" +
6618 " but the only thing we can do is adjust anyway, which will cause\n" +
6619 " some downstream failure.)\n" +
6620 " */\n" +
6621 "\n" +
6622 " MORECORE(-extra);\n" +
6623 " new_brk = (char*)(MORECORE(0));\n" +
6624 "\n" +
6625 " if (new_brk != (char*)MORECORE_FAILURE) {\n" +
6626 " released = (long)(current_brk - new_brk);\n" +
6627 "\n" +
6628 " if (released != 0) {\n" +
6629 " /* Success. Adjust top. */\n" +
6630 " av->sbrked_mem -= released;\n" +
6631 " set_head(av->top, (top_size - released) | PREV_INUSE);\n" +
6632 " check_malloc_state();\n" +
6633 " return 1;\n" +
6634 " }\n" +
6635 " }\n" +
6636 " }\n" +
6637 " }\n" +
6638 " return 0;\n" +
6639 "}\n" +
6640 "\n" +
6641 "#endif\n" +
6642 "\n" +
6643 "/*\n" +
6644 " ------------------------------ malloc ------------------------------\n" +
6645 "*/\n" +
6646 "\n" +
6647 "\n" +
6648 "#if __STD_C\n" +
6649 "Void_t* mALLOc(size_t bytes)\n" +
6650 "#else\n" +
6651 " Void_t* mALLOc(bytes) size_t bytes;\n" +
6652 "#endif\n" +
6653 "{\n" +
6654 " mstate av = get_malloc_state();\n" +
6655 "\n" +
6656 " INTERNAL_SIZE_T nb; /* normalized request size */\n" +
6657 " unsigned int idx; /* associated bin index */\n" +
6658 " mbinptr bin; /* associated bin */\n" +
6659 " mfastbinptr* fb; /* associated fastbin */\n" +
6660 "\n" +
6661 " mchunkptr victim; /* inspected/selected chunk */\n" +
6662 " INTERNAL_SIZE_T size; /* its size */\n" +
6663 " int victim_index; /* its bin index */\n" +
6664 "\n" +
6665 " mchunkptr remainder; /* remainder from a split */\n" +
6666 " CHUNK_SIZE_T remainder_size; /* its size */\n" +
6667 "\n" +
6668 " unsigned int block; /* bit map traverser */\n" +
6669 " unsigned int bit; /* bit map traverser */\n" +
6670 " unsigned int map; /* current word of binmap */\n" +
6671 "\n" +
6672 " mchunkptr fwd; /* misc temp for linking */\n" +
6673 " mchunkptr bck; /* misc temp for linking */\n" +
6674 "\n" +
6675 " /*\n" +
6676 " Convert request size to internal form by adding SIZE_SZ bytes\n" +
6677 " overhead plus possibly more to obtain necessary alignment and/or\n" +
6678 " to obtain a size of at least MINSIZE, the smallest allocatable\n" +
6679 " size. Also, checked_request2size traps (returning 0) request sizes\n" +
6680 " that are so large that they wrap around zero when padded and\n" +
6681 " aligned.\n" +
6682 " */\n" +
6683 "\n" +
6684 " checked_request2size(bytes, nb);\n" +
6685 "\n" +
6686 " /*\n" +
6687 " Bypass search if no frees yet\n" +
6688 " */\n" +
6689 " if (!have_anychunks(av)) {\n" +
6690 " if (av->max_fast == 0) /* initialization check */\n" +
6691 " malloc_consolidate(av);\n" +
6692 " goto use_top;\n" +
6693 " }\n" +
6694 "\n") +
6696 " /*\n" +
6697 " If the size qualifies as a fastbin, first check corresponding bin.\n" +
6698 " */\n" +
6699 "\n" +
6700 " if ((CHUNK_SIZE_T)(nb) <= (CHUNK_SIZE_T)(av->max_fast)) {\n" +
6701 " fb = &(av->fastbins[(fastbin_index(nb))]);\n" +
6702 " if ( (victim = *fb) != 0) {\n" +
6703 " *fb = victim->fd;\n" +
6704 " check_remalloced_chunk(victim, nb);\n" +
6705 " return chunk2mem(victim);\n" +
6706 " }\n" +
6707 " }\n" +
6708 "\n" +
6709 " /*\n" +
6710 " If a small request, check regular bin. Since these \"smallbins\"\n" +
6711 " hold one size each, no searching within bins is necessary.\n" +
6712 " (For a large request, we need to wait until unsorted chunks are\n" +
6713 " processed to find best fit. But for small ones, fits are exact\n" +
6714 " anyway, so we can check now, which is faster.)\n" +
6715 " */\n" +
6716 "\n" +
6717 " if (in_smallbin_range(nb)) {\n" +
6718 " idx = smallbin_index(nb);\n" +
6719 " bin = bin_at(av,idx);\n" +
6720 "\n" +
6721 " if ( (victim = last(bin)) != bin) {\n" +
6722 " bck = victim->bk;\n" +
6723 " set_inuse_bit_at_offset(victim, nb);\n" +
6724 " bin->bk = bck;\n" +
6725 " bck->fd = bin;\n" +
6726 "\n" +
6727 " check_malloced_chunk(victim, nb);\n" +
6728 " return chunk2mem(victim);\n" +
6729 " }\n" +
6730 " }\n" +
6731 "\n" +
6732 " /*\n" +
6733 " If this is a large request, consolidate fastbins before continuing.\n" +
6734 " While it might look excessive to kill all fastbins before\n" +
6735 " even seeing if there is space available, this avoids\n" +
6736 " fragmentation problems normally associated with fastbins.\n" +
6737 " Also, in practice, programs tend to have runs of either small or\n" +
6738 " large requests, but less often mixtures, so consolidation is not\n" +
6739 " invoked all that often in most programs. And the programs that\n" +
6740 " it is called frequently in otherwise tend to fragment.\n" +
6741 " */\n" +
6742 "\n" +
6743 " else {\n" +
6744 " idx = largebin_index(nb);\n" +
6745 " if (have_fastchunks(av))\n" +
6746 " malloc_consolidate(av);\n" +
6747 " }\n" +
6748 "\n" +
6749 " /*\n" +
6750 " Process recently freed or remaindered chunks, taking one only if\n" +
6751 " it is exact fit, or, if this a small request, the chunk is remainder from\n" +
6752 " the most recent non-exact fit. Place other traversed chunks in\n" +
6753 " bins. Note that this step is the only place in any routine where\n" +
6754 " chunks are placed in bins.\n" +
6755 " */\n" +
6756 "\n" +
6757 " while ( (victim = unsorted_chunks(av)->bk) != unsorted_chunks(av)) {\n" +
6758 " bck = victim->bk;\n" +
6759 " size = chunksize(victim);\n" +
6760 "\n" +
6761 " /*\n" +
6762 " If a small request, try to use last remainder if it is the\n" +
6763 " only chunk in unsorted bin. This helps promote locality for\n" +
6764 " runs of consecutive small requests. This is the only\n" +
6765 " exception to best-fit, and applies only when there is\n" +
6766 " no exact fit for a small chunk.\n" +
6767 " */\n" +
6768 "\n" +
6769 " if (in_smallbin_range(nb) &&\n" +
6770 " bck == unsorted_chunks(av) &&\n" +
6771 " victim == av->last_remainder &&\n" +
6772 " (CHUNK_SIZE_T)(size) > (CHUNK_SIZE_T)(nb + MINSIZE)) {\n" +
6773 "\n" +
6774 " /* split and reattach remainder */\n" +
6775 " remainder_size = size - nb;\n" +
6776 " remainder = chunk_at_offset(victim, nb);\n" +
6777 " unsorted_chunks(av)->bk = unsorted_chunks(av)->fd = remainder;\n" +
6778 " av->last_remainder = remainder;\n" +
6779 " remainder->bk = remainder->fd = unsorted_chunks(av);\n" +
6780 "\n" +
6781 " set_head(victim, nb | PREV_INUSE);\n" +
6782 " set_head(remainder, remainder_size | PREV_INUSE);\n" +
6783 " set_foot(remainder, remainder_size);\n" +
6784 "\n" +
6785 " check_malloced_chunk(victim, nb);\n" +
6786 " return chunk2mem(victim);\n" +
6787 " }\n" +
6788 "\n" +
6789 " /* remove from unsorted list */\n" +
6790 " unsorted_chunks(av)->bk = bck;\n" +
6791 " bck->fd = unsorted_chunks(av);\n" +
6792 "\n" +
6793 " /* Take now instead of binning if exact fit */\n" +
6794 "\n" +
6795 " if (size == nb) {\n" +
6796 " set_inuse_bit_at_offset(victim, size);\n" +
6797 " check_malloced_chunk(victim, nb);\n" +
6798 " return chunk2mem(victim);\n" +
6799 " }\n" +
6800 "\n" +
6801 " /* place chunk in bin */\n" +
6802 "\n" +
6803 " if (in_smallbin_range(size)) {\n" +
6804 " victim_index = smallbin_index(size);\n" +
6805 " bck = bin_at(av, victim_index);\n" +
6806 " fwd = bck->fd;\n" +
6807 " }\n" +
6808 " else {\n" +
6809 " victim_index = largebin_index(size);\n" +
6810 " bck = bin_at(av, victim_index);\n" +
6811 " fwd = bck->fd;\n" +
6812 "\n" +
6813 " if (fwd != bck) {\n" +
6814 " /* if smaller than smallest, place first */\n" +
6815 " if ((CHUNK_SIZE_T)(size) < (CHUNK_SIZE_T)(bck->bk->size)) {\n" +
6816 " fwd = bck;\n" +
6817 " bck = bck->bk;\n" +
6818 " }\n" +
6819 " else if ((CHUNK_SIZE_T)(size) >=\n" +
6820 " (CHUNK_SIZE_T)(FIRST_SORTED_BIN_SIZE)) {\n" +
6821 "\n" +
6822 " /* maintain large bins in sorted order */\n" +
6823 " size |= PREV_INUSE; /* Or with inuse bit to speed comparisons */\n" +
6824 " while ((CHUNK_SIZE_T)(size) < (CHUNK_SIZE_T)(fwd->size))\n" +
6825 " fwd = fwd->fd;\n" +
6826 " bck = fwd->bk;\n" +
6827 " }\n" +
6828 " }\n" +
6829 " }\n" +
6830 "\n" +
6831 " mark_bin(av, victim_index);\n" +
6832 " victim->bk = bck;\n" +
6833 " victim->fd = fwd;\n" +
6834 " fwd->bk = victim;\n" +
6835 " bck->fd = victim;\n" +
6836 " }\n" +
6837 "\n" +
6838 " /*\n" +
6839 " If a large request, scan through the chunks of current bin to\n" +
6840 " find one that fits. (This will be the smallest that fits unless\n" +
6841 " FIRST_SORTED_BIN_SIZE has been changed from default.) This is\n" +
6842 " the only step where an unbounded number of chunks might be\n" +
6843 " scanned without doing anything useful with them. However the\n" +
6844 " lists tend to be short.\n" +
6845 " */\n" +
6846 "\n") +
6848 " if (!in_smallbin_range(nb)) {\n" +
6849 " bin = bin_at(av, idx);\n" +
6850 "\n" +
6851 " for (victim = last(bin); victim != bin; victim = victim->bk) {\n" +
6852 " size = chunksize(victim);\n" +
6853 "\n" +
6854 " if ((CHUNK_SIZE_T)(size) >= (CHUNK_SIZE_T)(nb)) {\n" +
6855 " remainder_size = size - nb;\n" +
6856 " unlink(victim, bck, fwd);\n" +
6857 "\n" +
6858 " /* Exhaust */\n" +
6859 " if (remainder_size < MINSIZE) {\n" +
6860 " set_inuse_bit_at_offset(victim, size);\n" +
6861 " check_malloced_chunk(victim, nb);\n" +
6862 " return chunk2mem(victim);\n" +
6863 " }\n" +
6864 " /* Split */\n" +
6865 " else {\n" +
6866 " remainder = chunk_at_offset(victim, nb);\n" +
6867 " unsorted_chunks(av)->bk = unsorted_chunks(av)->fd = remainder;\n" +
6868 " remainder->bk = remainder->fd = unsorted_chunks(av);\n" +
6869 " set_head(victim, nb | PREV_INUSE);\n" +
6870 " set_head(remainder, remainder_size | PREV_INUSE);\n" +
6871 " set_foot(remainder, remainder_size);\n" +
6872 " check_malloced_chunk(victim, nb);\n" +
6873 " return chunk2mem(victim);\n" +
6874 " }\n" +
6875 " }\n" +
6876 " }\n" +
6877 " }\n" +
6878 "\n" +
6879 " /*\n" +
6880 " Search for a chunk by scanning bins, starting with next largest\n" +
6881 " bin. This search is strictly by best-fit; i.e., the smallest\n" +
6882 " (with ties going to approximately the least recently used) chunk\n" +
6883 " that fits is selected.\n" +
6884 "\n" +
6885 " The bitmap avoids needing to check that most blocks are nonempty.\n" +
6886 " */\n" +
6887 "\n" +
6888 " ++idx;\n" +
6889 " bin = bin_at(av,idx);\n" +
6890 " block = idx2block(idx);\n" +
6891 " map = av->binmap[block];\n" +
6892 " bit = idx2bit(idx);\n" +
6893 "\n" +
6894 " for (;;) {\n" +
6895 "\n" +
6896 " /* Skip rest of block if there are no more set bits in this block. */\n" +
6897 " if (bit > map || bit == 0) {\n" +
6898 " do {\n" +
6899 " if (++block >= BINMAPSIZE) /* out of bins */\n" +
6900 " goto use_top;\n" +
6901 " } while ( (map = av->binmap[block]) == 0);\n" +
6902 "\n" +
6903 " bin = bin_at(av, (block << BINMAPSHIFT));\n" +
6904 " bit = 1;\n" +
6905 " }\n" +
6906 "\n" +
6907 " /* Advance to bin with set bit. There must be one. */\n" +
6908 " while ((bit & map) == 0) {\n" +
6909 " bin = next_bin(bin);\n" +
6910 " bit <<= 1;\n" +
6911 " assert(bit != 0);\n" +
6912 " }\n" +
6913 "\n" +
6914 " /* Inspect the bin. It is likely to be non-empty */\n" +
6915 " victim = last(bin);\n" +
6916 "\n" +
6917 " /* If a false alarm (empty bin), clear the bit. */\n" +
6918 " if (victim == bin) {\n" +
6919 " av->binmap[block] = map &= ~bit; /* Write through */\n" +
6920 " bin = next_bin(bin);\n" +
6921 " bit <<= 1;\n" +
6922 " }\n" +
6923 "\n" +
6924 " else {\n" +
6925 " size = chunksize(victim);\n" +
6926 "\n" +
6927 " /* We know the first chunk in this bin is big enough to use. */\n" +
6928 " assert((CHUNK_SIZE_T)(size) >= (CHUNK_SIZE_T)(nb));\n" +
6929 "\n" +
6930 " remainder_size = size - nb;\n" +
6931 "\n" +
6932 " /* unlink */\n" +
6933 " bck = victim->bk;\n" +
6934 " bin->bk = bck;\n" +
6935 " bck->fd = bin;\n" +
6936 "\n" +
6937 " /* Exhaust */\n" +
6938 " if (remainder_size < MINSIZE) {\n" +
6939 " set_inuse_bit_at_offset(victim, size);\n" +
6940 " check_malloced_chunk(victim, nb);\n" +
6941 " return chunk2mem(victim);\n" +
6942 " }\n" +
6943 "\n" +
6944 " /* Split */\n" +
6945 " else {\n" +
6946 " remainder = chunk_at_offset(victim, nb);\n" +
6947 "\n" +
6948 " unsorted_chunks(av)->bk = unsorted_chunks(av)->fd = remainder;\n" +
6949 " remainder->bk = remainder->fd = unsorted_chunks(av);\n" +
6950 " /* advertise as last remainder */\n" +
6951 " if (in_smallbin_range(nb))\n" +
6952 " av->last_remainder = remainder;\n" +
6953 "\n" +
6954 " set_head(victim, nb | PREV_INUSE);\n" +
6955 " set_head(remainder, remainder_size | PREV_INUSE);\n" +
6956 " set_foot(remainder, remainder_size);\n" +
6957 " check_malloced_chunk(victim, nb);\n" +
6958 " return chunk2mem(victim);\n" +
6959 " }\n" +
6960 " }\n" +
6961 " }\n" +
6962 "\n" +
6963 " use_top:\n" +
6964 " /*\n" +
6965 " If large enough, split off the chunk bordering the end of memory\n" +
6966 " (held in av->top). Note that this is in accord with the best-fit\n" +
6967 " search rule. In effect, av->top is treated as larger (and thus\n" +
6968 " less well fitting) than any other available chunk since it can\n" +
6969 " be extended to be as large as necessary (up to system\n" +
6970 " limitations).\n" +
6971 "\n" +
6972 " We require that av->top always exists (i.e., has size >=\n" +
6973 " MINSIZE) after initialization, so if it would otherwise be\n" +
6974 " exhuasted by current request, it is replenished. (The main\n" +
6975 " reason for ensuring it exists is that we may need MINSIZE space\n" +
6976 " to put in fenceposts in sysmalloc.)\n" +
6977 " */\n" +
6978 "\n" +
6979 " victim = av->top;\n" +
6980 " size = chunksize(victim);\n" +
6981 "\n" +
6982 " if ((CHUNK_SIZE_T)(size) >= (CHUNK_SIZE_T)(nb + MINSIZE)) {\n" +
6983 " remainder_size = size - nb;\n" +
6984 " remainder = chunk_at_offset(victim, nb);\n" +
6985 " av->top = remainder;\n" +
6986 " set_head(victim, nb | PREV_INUSE);\n" +
6987 " set_head(remainder, remainder_size | PREV_INUSE);\n" +
6988 "\n" +
6989 " check_malloced_chunk(victim, nb);\n" +
6990 " return chunk2mem(victim);\n" +
6991 " }\n" +
6992 "\n" +
6993 " /*\n" +
6994 " If no space in top, relay to handle system-dependent cases\n" +
6995 " */\n" +
6996 " return sYSMALLOc(nb, av);\n" +
6997 "}\n" +
6998 "\n") +
7000 "/*\n" +
7001 " ------------------------------ free ------------------------------\n" +
7002 "*/\n" +
7003 "\n" +
7004 "#if __STD_C\n" +
7005 "void fREe(Void_t* mem)\n" +
7006 "#else\n" +
7007 "void fREe(mem) Void_t* mem;\n" +
7008 "#endif\n" +
7009 "{\n" +
7010 " mstate av = get_malloc_state();\n" +
7011 "\n" +
7012 " mchunkptr p; /* chunk corresponding to mem */\n" +
7013 " INTERNAL_SIZE_T size; /* its size */\n" +
7014 " mfastbinptr* fb; /* associated fastbin */\n" +
7015 " mchunkptr nextchunk; /* next contiguous chunk */\n" +
7016 " INTERNAL_SIZE_T nextsize; /* its size */\n" +
7017 " int nextinuse; /* true if nextchunk is used */\n" +
7018 " INTERNAL_SIZE_T prevsize; /* size of previous contiguous chunk */\n" +
7019 " mchunkptr bck; /* misc temp for linking */\n" +
7020 " mchunkptr fwd; /* misc temp for linking */\n" +
7021 "\n" +
7022 " /* free(0) has no effect */\n" +
7023 " if (mem != 0) {\n" +
7024 " p = mem2chunk(mem);\n" +
7025 " size = chunksize(p);\n" +
7026 "\n" +
7027 " check_inuse_chunk(p);\n" +
7028 "\n" +
7029 " /*\n" +
7030 " If eligible, place chunk on a fastbin so it can be found\n" +
7031 " and used quickly in malloc.\n" +
7032 " */\n" +
7033 "\n" +
7034 " if ((CHUNK_SIZE_T)(size) <= (CHUNK_SIZE_T)(av->max_fast)\n" +
7035 "\n" +
7036 "#if TRIM_FASTBINS\n" +
7037 " /*\n" +
7038 " If TRIM_FASTBINS set, don't place chunks\n" +
7039 " bordering top into fastbins\n" +
7040 " */\n" +
7041 " && (chunk_at_offset(p, size) != av->top)\n" +
7042 "#endif\n" +
7043 " ) {\n" +
7044 "\n" +
7045 " set_fastchunks(av);\n" +
7046 " fb = &(av->fastbins[fastbin_index(size)]);\n" +
7047 " p->fd = *fb;\n" +
7048 " *fb = p;\n" +
7049 " }\n" +
7050 "\n" +
7051 " /*\n" +
7052 " Consolidate other non-mmapped chunks as they arrive.\n" +
7053 " */\n" +
7054 "\n" +
7055 " else if (!chunk_is_mmapped(p)) {\n" +
7056 " set_anychunks(av);\n" +
7057 "\n" +
7058 " nextchunk = chunk_at_offset(p, size);\n" +
7059 " nextsize = chunksize(nextchunk);\n" +
7060 "\n" +
7061 " /* consolidate backward */\n" +
7062 " if (!prev_inuse(p)) {\n" +
7063 " prevsize = p->prev_size;\n" +
7064 " size += prevsize;\n" +
7065 " p = chunk_at_offset(p, -((long) prevsize));\n" +
7066 " unlink(p, bck, fwd);\n" +
7067 " }\n" +
7068 "\n" +
7069 " if (nextchunk != av->top) {\n" +
7070 " /* get and clear inuse bit */\n" +
7071 " nextinuse = inuse_bit_at_offset(nextchunk, nextsize);\n" +
7072 " set_head(nextchunk, nextsize);\n" +
7073 "\n" +
7074 " /* consolidate forward */\n" +
7075 " if (!nextinuse) {\n" +
7076 " unlink(nextchunk, bck, fwd);\n" +
7077 " size += nextsize;\n" +
7078 " }\n" +
7079 "\n" +
7080 " /*\n" +
7081 " Place the chunk in unsorted chunk list. Chunks are\n" +
7082 " not placed into regular bins until after they have\n" +
7083 " been given one chance to be used in malloc.\n" +
7084 " */\n" +
7085 "\n" +
7086 " bck = unsorted_chunks(av);\n" +
7087 " fwd = bck->fd;\n" +
7088 " p->bk = bck;\n" +
7089 " p->fd = fwd;\n" +
7090 " bck->fd = p;\n" +
7091 " fwd->bk = p;\n" +
7092 "\n" +
7093 " set_head(p, size | PREV_INUSE);\n" +
7094 " set_foot(p, size);\n" +
7095 "\n" +
7096 " check_free_chunk(p);\n" +
7097 " }\n" +
7098 "\n" +
7099 " /*\n" +
7100 " If the chunk borders the current high end of memory,\n" +
7101 " consolidate into top\n" +
7102 " */\n" +
7103 "\n" +
7104 " else {\n" +
7105 " size += nextsize;\n" +
7106 " set_head(p, size | PREV_INUSE);\n" +
7107 " av->top = p;\n" +
7108 " check_chunk(p);\n" +
7109 " }\n" +
7110 "\n" +
7111 " /*\n" +
7112 " If freeing a large space, consolidate possibly-surrounding\n" +
7113 " chunks. Then, if the total unused topmost memory exceeds trim\n" +
7114 " threshold, ask malloc_trim to reduce top.\n" +
7115 "\n" +
7116 " Unless max_fast is 0, we don't know if there are fastbins\n" +
7117 " bordering top, so we cannot tell for sure whether threshold\n" +
7118 " has been reached unless fastbins are consolidated. But we\n" +
7119 " don't want to consolidate on each free. As a compromise,\n" +
7120 " consolidation is performed if FASTBIN_CONSOLIDATION_THRESHOLD\n" +
7121 " is reached.\n" +
7122 " */\n" +
7123 "\n" +
7124 " if ((CHUNK_SIZE_T)(size) >= FASTBIN_CONSOLIDATION_THRESHOLD) {\n" +
7125 " if (have_fastchunks(av))\n" +
7126 " malloc_consolidate(av);\n" +
7127 "\n" +
7128 "#ifndef MORECORE_CANNOT_TRIM\n" +
7129 " if ((CHUNK_SIZE_T)(chunksize(av->top)) >=\n" +
7130 " (CHUNK_SIZE_T)(av->trim_threshold))\n" +
7131 " sYSTRIm(av->top_pad, av);\n" +
7132 "#endif\n" +
7133 " }\n" +
7134 "\n" +
7135 " }\n" +
7136 " /*\n" +
7137 " If the chunk was allocated via mmap, release via munmap()\n" +
7138 " Note that if HAVE_MMAP is false but chunk_is_mmapped is\n" +
7139 " true, then user must have overwritten memory. There's nothing\n" +
7140 " we can do to catch this error unless DEBUG is set, in which case\n" +
7141 " check_inuse_chunk (above) will have triggered error.\n" +
7142 " */\n" +
7143 "\n" +
7144 " else {\n" +
7145 "#if HAVE_MMAP\n" +
7146 " int ret;\n" +
7147 " INTERNAL_SIZE_T offset = p->prev_size;\n" +
7148 " av->n_mmaps--;\n" +
7149 " av->mmapped_mem -= (size + offset);\n" +
7150 " ret = munmap((char*)p - offset, size + offset);\n" +
7151 " /* munmap returns non-zero on failure */\n" +
7152 " assert(ret == 0);\n" +
7153 "#endif\n" +
7154 " }\n" +
7155 " }\n" +
7156 "}\n" +
7157 "\n") +
7159 "/*\n" +
7160 " ------------------------- malloc_consolidate -------------------------\n" +
7161 "\n" +
7162 " malloc_consolidate is a specialized version of free() that tears\n" +
7163 " down chunks held in fastbins. Free itself cannot be used for this\n" +
7164 " purpose since, among other things, it might place chunks back onto\n" +
7165 " fastbins. So, instead, we need to use a minor variant of the same\n" +
7166 " code.\n" +
7167 "\n" +
7168 " Also, because this routine needs to be called the first time through\n" +
7169 " malloc anyway, it turns out to be the perfect place to trigger\n" +
7170 " initialization code.\n" +
7171 "*/\n" +
7172 "\n" +
7173 "#if __STD_C\n" +
7174 "static void malloc_consolidate(mstate av)\n" +
7175 "#else\n" +
7176 "static void malloc_consolidate(av) mstate av;\n" +
7177 "#endif\n" +
7178 "{\n" +
7179 " mfastbinptr* fb; /* current fastbin being consolidated */\n" +
7180 " mfastbinptr* maxfb; /* last fastbin (for loop control) */\n" +
7181 " mchunkptr p; /* current chunk being consolidated */\n" +
7182 " mchunkptr nextp; /* next chunk to consolidate */\n" +
7183 " mchunkptr unsorted_bin; /* bin header */\n" +
7184 " mchunkptr first_unsorted; /* chunk to link to */\n" +
7185 "\n" +
7186 " /* These have same use as in free() */\n" +
7187 " mchunkptr nextchunk;\n" +
7188 " INTERNAL_SIZE_T size;\n" +
7189 " INTERNAL_SIZE_T nextsize;\n" +
7190 " INTERNAL_SIZE_T prevsize;\n" +
7191 " int nextinuse;\n" +
7192 " mchunkptr bck;\n" +
7193 " mchunkptr fwd;\n" +
7194 "\n" +
7195 " /*\n" +
7196 " If max_fast is 0, we know that av hasn't\n" +
7197 " yet been initialized, in which case do so below\n" +
7198 " */\n" +
7199 "\n" +
7200 " if (av->max_fast != 0) {\n" +
7201 " clear_fastchunks(av);\n" +
7202 "\n" +
7203 " unsorted_bin = unsorted_chunks(av);\n" +
7204 "\n" +
7205 " /*\n" +
7206 " Remove each chunk from fast bin and consolidate it, placing it\n" +
7207 " then in unsorted bin. Among other reasons for doing this,\n" +
7208 " placing in unsorted bin avoids needing to calculate actual bins\n" +
7209 " until malloc is sure that chunks aren't immediately going to be\n" +
7210 " reused anyway.\n" +
7211 " */\n" +
7212 "\n" +
7213 " maxfb = &(av->fastbins[fastbin_index(av->max_fast)]);\n" +
7214 " fb = &(av->fastbins[0]);\n" +
7215 " do {\n" +
7216 " if ( (p = *fb) != 0) {\n" +
7217 " *fb = 0;\n" +
7218 "\n" +
7219 " do {\n" +
7220 " check_inuse_chunk(p);\n" +
7221 " nextp = p->fd;\n" +
7222 "\n" +
7223 " /* Slightly streamlined version of consolidation code in free() */\n" +
7224 " size = p->size & ~PREV_INUSE;\n" +
7225 " nextchunk = chunk_at_offset(p, size);\n" +
7226 " nextsize = chunksize(nextchunk);\n" +
7227 "\n" +
7228 " if (!prev_inuse(p)) {\n" +
7229 " prevsize = p->prev_size;\n" +
7230 " size += prevsize;\n" +
7231 " p = chunk_at_offset(p, -((long) prevsize));\n" +
7232 " unlink(p, bck, fwd);\n" +
7233 " }\n" +
7234 "\n" +
7235 " if (nextchunk != av->top) {\n" +
7236 " nextinuse = inuse_bit_at_offset(nextchunk, nextsize);\n" +
7237 " set_head(nextchunk, nextsize);\n" +
7238 "\n" +
7239 " if (!nextinuse) {\n" +
7240 " size += nextsize;\n" +
7241 " unlink(nextchunk, bck, fwd);\n" +
7242 " }\n" +
7243 "\n" +
7244 " first_unsorted = unsorted_bin->fd;\n" +
7245 " unsorted_bin->fd = p;\n" +
7246 " first_unsorted->bk = p;\n" +
7247 "\n" +
7248 " set_head(p, size | PREV_INUSE);\n" +
7249 " p->bk = unsorted_bin;\n" +
7250 " p->fd = first_unsorted;\n" +
7251 " set_foot(p, size);\n" +
7252 " }\n" +
7253 "\n" +
7254 " else {\n" +
7255 " size += nextsize;\n" +
7256 " set_head(p, size | PREV_INUSE);\n" +
7257 " av->top = p;\n" +
7258 " }\n" +
7259 "\n" +
7260 " } while ( (p = nextp) != 0);\n" +
7261 "\n" +
7262 " }\n" +
7263 " } while (fb++ != maxfb);\n" +
7264 " }\n" +
7265 " else {\n" +
7266 " malloc_init_state(av);\n" +
7267 " check_malloc_state();\n" +
7268 " }\n" +
7269 "}\n" +
7270 "\n" +
7271 "/*\n" +
7272 " ------------------------------ realloc ------------------------------\n" +
7273 "*/\n" +
7274 "\n" +
7275 "\n" +
7276 "#if __STD_C\n" +
7277 "Void_t* rEALLOc(Void_t* oldmem, size_t bytes)\n" +
7278 "#else\n" +
7279 "Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes;\n" +
7280 "#endif\n" +
7281 "{\n" +
7282 " mstate av = get_malloc_state();\n" +
7283 "\n" +
7284 " INTERNAL_SIZE_T nb; /* padded request size */\n" +
7285 "\n" +
7286 " mchunkptr oldp; /* chunk corresponding to oldmem */\n" +
7287 " INTERNAL_SIZE_T oldsize; /* its size */\n" +
7288 "\n" +
7289 " mchunkptr newp; /* chunk to return */\n" +
7290 " INTERNAL_SIZE_T newsize; /* its size */\n" +
7291 " Void_t* newmem; /* corresponding user mem */\n" +
7292 "\n" +
7293 " mchunkptr next; /* next contiguous chunk after oldp */\n" +
7294 "\n" +
7295 " mchunkptr remainder; /* extra space at end of newp */\n" +
7296 " CHUNK_SIZE_T remainder_size; /* its size */\n" +
7297 "\n" +
7298 " mchunkptr bck; /* misc temp for linking */\n" +
7299 " mchunkptr fwd; /* misc temp for linking */\n" +
7300 "\n" +
7301 " CHUNK_SIZE_T copysize; /* bytes to copy */\n" +
7302 " unsigned int ncopies; /* INTERNAL_SIZE_T words to copy */\n" +
7303 " INTERNAL_SIZE_T* s; /* copy source */\n" +
7304 " INTERNAL_SIZE_T* d; /* copy destination */\n" +
7305 "\n" +
7306 "\n" +
7307 "#ifdef REALLOC_ZERO_BYTES_FREES\n" +
7308 " if (bytes == 0) {\n" +
7309 " fREe(oldmem);\n" +
7310 " return 0;\n" +
7311 " }\n" +
7312 "#endif\n" +
7313 "\n") +
7315 " /* realloc of null is supposed to be same as malloc */\n" +
7316 " if (oldmem == 0) return mALLOc(bytes);\n" +
7317 "\n" +
7318 " checked_request2size(bytes, nb);\n" +
7319 "\n" +
7320 " oldp = mem2chunk(oldmem);\n" +
7321 " oldsize = chunksize(oldp);\n" +
7322 "\n" +
7323 " check_inuse_chunk(oldp);\n" +
7324 "\n" +
7325 " if (!chunk_is_mmapped(oldp)) {\n" +
7326 "\n" +
7327 " if ((CHUNK_SIZE_T)(oldsize) >= (CHUNK_SIZE_T)(nb)) {\n" +
7328 " /* already big enough; split below */\n" +
7329 " newp = oldp;\n" +
7330 " newsize = oldsize;\n" +
7331 " }\n" +
7332 "\n" +
7333 " else {\n" +
7334 " next = chunk_at_offset(oldp, oldsize);\n" +
7335 "\n" +
7336 " /* Try to expand forward into top */\n" +
7337 " if (next == av->top &&\n" +
7338 " (CHUNK_SIZE_T)(newsize = oldsize + chunksize(next)) >=\n" +
7339 " (CHUNK_SIZE_T)(nb + MINSIZE)) {\n" +
7340 " set_head_size(oldp, nb);\n" +
7341 " av->top = chunk_at_offset(oldp, nb);\n" +
7342 " set_head(av->top, (newsize - nb) | PREV_INUSE);\n" +
7343 " return chunk2mem(oldp);\n" +
7344 " }\n" +
7345 "\n" +
7346 " /* Try to expand forward into next chunk; split off remainder below */\n" +
7347 " else if (next != av->top &&\n" +
7348 " !inuse(next) &&\n" +
7349 " (CHUNK_SIZE_T)(newsize = oldsize + chunksize(next)) >=\n" +
7350 " (CHUNK_SIZE_T)(nb)) {\n" +
7351 " newp = oldp;\n" +
7352 " unlink(next, bck, fwd);\n" +
7353 " }\n" +
7354 "\n" +
7355 " /* allocate, copy, free */\n" +
7356 " else {\n" +
7357 " newmem = mALLOc(nb - MALLOC_ALIGN_MASK);\n" +
7358 " if (newmem == 0)\n" +
7359 " return 0; /* propagate failure */\n" +
7360 "\n" +
7361 " newp = mem2chunk(newmem);\n" +
7362 " newsize = chunksize(newp);\n" +
7363 "\n" +
7364 " /*\n" +
7365 " Avoid copy if newp is next chunk after oldp.\n" +
7366 " */\n" +
7367 " if (newp == next) {\n" +
7368 " newsize += oldsize;\n" +
7369 " newp = oldp;\n" +
7370 " }\n" +
7371 " else {\n" +
7372 " /*\n" +
7373 " Unroll copy of <= 36 bytes (72 if 8byte sizes)\n" +
7374 " We know that contents have an odd number of\n" +
7375 " INTERNAL_SIZE_T-sized words; minimally 3.\n" +
7376 " */\n" +
7377 "\n" +
7378 " copysize = oldsize - SIZE_SZ;\n" +
7379 " s = (INTERNAL_SIZE_T*)(oldmem);\n" +
7380 " d = (INTERNAL_SIZE_T*)(newmem);\n" +
7381 " ncopies = copysize / sizeof(INTERNAL_SIZE_T);\n" +
7382 " assert(ncopies >= 3);\n" +
7383 "\n" +
7384 " if (ncopies > 9)\n" +
7385 " MALLOC_COPY(d, s, copysize);\n" +
7386 "\n" +
7387 " else {\n" +
7388 " *(d+0) = *(s+0);\n" +
7389 " *(d+1) = *(s+1);\n" +
7390 " *(d+2) = *(s+2);\n" +
7391 " if (ncopies > 4) {\n" +
7392 " *(d+3) = *(s+3);\n" +
7393 " *(d+4) = *(s+4);\n" +
7394 " if (ncopies > 6) {\n" +
7395 " *(d+5) = *(s+5);\n" +
7396 " *(d+6) = *(s+6);\n" +
7397 " if (ncopies > 8) {\n" +
7398 " *(d+7) = *(s+7);\n" +
7399 " *(d+8) = *(s+8);\n" +
7400 " }\n" +
7401 " }\n" +
7402 " }\n" +
7403 " }\n" +
7404 "\n" +
7405 " fREe(oldmem);\n" +
7406 " check_inuse_chunk(newp);\n" +
7407 " return chunk2mem(newp);\n" +
7408 " }\n" +
7409 " }\n" +
7410 " }\n" +
7411 "\n" +
7412 " /* If possible, free extra space in old or extended chunk */\n" +
7413 "\n" +
7414 " assert((CHUNK_SIZE_T)(newsize) >= (CHUNK_SIZE_T)(nb));\n" +
7415 "\n" +
7416 " remainder_size = newsize - nb;\n" +
7417 "\n" +
7418 " if (remainder_size < MINSIZE) { /* not enough extra to split off */\n" +
7419 " set_head_size(newp, newsize);\n" +
7420 " set_inuse_bit_at_offset(newp, newsize);\n" +
7421 " }\n" +
7422 " else { /* split remainder */\n" +
7423 " remainder = chunk_at_offset(newp, nb);\n" +
7424 " set_head_size(newp, nb);\n" +
7425 " set_head(remainder, remainder_size | PREV_INUSE);\n" +
7426 " /* Mark remainder as inuse so free() won't complain */\n" +
7427 " set_inuse_bit_at_offset(remainder, remainder_size);\n" +
7428 " fREe(chunk2mem(remainder));\n" +
7429 " }\n" +
7430 "\n" +
7431 " check_inuse_chunk(newp);\n" +
7432 " return chunk2mem(newp);\n" +
7433 " }\n" +
7434 "\n" +
7435 " /*\n" +
7436 " Handle mmap cases\n" +
7437 " */\n" +
7438 "\n" +
7439 " else {\n" +
7440 "#if HAVE_MMAP\n" +
7441 "\n" +
7442 "#if HAVE_MREMAP\n" +
7443 " INTERNAL_SIZE_T offset = oldp->prev_size;\n" +
7444 " size_t pagemask = av->pagesize - 1;\n" +
7445 " char *cp;\n" +
7446 " CHUNK_SIZE_T sum;\n" +
7447 "\n" +
7448 " /* Note the extra SIZE_SZ overhead */\n" +
7449 " newsize = (nb + offset + SIZE_SZ + pagemask) & ~pagemask;\n" +
7450 "\n" +
7451 " /* don't need to remap if still within same page */\n" +
7452 " if (oldsize == newsize - offset)\n" +
7453 " return oldmem;\n" +
7454 "\n" +
7455 " cp = (char*)mremap((char*)oldp - offset, oldsize + offset, newsize, 1);\n" +
7456 "\n" +
7457 " if (cp != (char*)MORECORE_FAILURE) {\n" +
7458 "\n" +
7459 " newp = (mchunkptr)(cp + offset);\n" +
7460 " set_head(newp, (newsize - offset)|IS_MMAPPED);\n" +
7461 "\n" +
7462 " assert(aligned_OK(chunk2mem(newp)));\n" +
7463 " assert((newp->prev_size == offset));\n" +
7464 "\n") +
7466 " /* update statistics */\n" +
7467 " sum = av->mmapped_mem += newsize - oldsize;\n" +
7468 " if (sum > (CHUNK_SIZE_T)(av->max_mmapped_mem))\n" +
7469 " av->max_mmapped_mem = sum;\n" +
7470 " sum += av->sbrked_mem;\n" +
7471 " if (sum > (CHUNK_SIZE_T)(av->max_total_mem))\n" +
7472 " av->max_total_mem = sum;\n" +
7473 "\n" +
7474 " return chunk2mem(newp);\n" +
7475 " }\n" +
7476 "#endif\n" +
7477 "\n" +
7478 " /* Note the extra SIZE_SZ overhead. */\n" +
7479 " if ((CHUNK_SIZE_T)(oldsize) >= (CHUNK_SIZE_T)(nb + SIZE_SZ))\n" +
7480 " newmem = oldmem; /* do nothing */\n" +
7481 " else {\n" +
7482 " /* Must alloc, copy, free. */\n" +
7483 " newmem = mALLOc(nb - MALLOC_ALIGN_MASK);\n" +
7484 " if (newmem != 0) {\n" +
7485 " MALLOC_COPY(newmem, oldmem, oldsize - 2*SIZE_SZ);\n" +
7486 " fREe(oldmem);\n" +
7487 " }\n" +
7488 " }\n" +
7489 " return newmem;\n" +
7490 "\n" +
7491 "#else\n" +
7492 " /* If !HAVE_MMAP, but chunk_is_mmapped, user must have overwritten mem */\n" +
7493 " check_malloc_state();\n" +
7494 " MALLOC_FAILURE_ACTION;\n" +
7495 " return 0;\n" +
7496 "#endif\n" +
7497 " }\n" +
7498 "}\n" +
7499 "\n" +
7500 "/*\n" +
7501 " ------------------------------ memalign ------------------------------\n" +
7502 "*/\n" +
7503 "\n" +
7504 "#if __STD_C\n" +
7505 "Void_t* mEMALIGn(size_t alignment, size_t bytes)\n" +
7506 "#else\n" +
7507 "Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;\n" +
7508 "#endif\n" +
7509 "{\n" +
7510 " INTERNAL_SIZE_T nb; /* padded request size */\n" +
7511 " char* m; /* memory returned by malloc call */\n" +
7512 " mchunkptr p; /* corresponding chunk */\n" +
7513 " char* brk; /* alignment point within p */\n" +
7514 " mchunkptr newp; /* chunk to return */\n" +
7515 " INTERNAL_SIZE_T newsize; /* its size */\n" +
7516 " INTERNAL_SIZE_T leadsize; /* leading space before alignment point */\n" +
7517 " mchunkptr remainder; /* spare room at end to split off */\n" +
7518 " CHUNK_SIZE_T remainder_size; /* its size */\n" +
7519 " INTERNAL_SIZE_T size;\n" +
7520 "\n" +
7521 " /* If need less alignment than we give anyway, just relay to malloc */\n" +
7522 "\n" +
7523 " if (alignment <= MALLOC_ALIGNMENT) return mALLOc(bytes);\n" +
7524 "\n" +
7525 " /* Otherwise, ensure that it is at least a minimum chunk size */\n" +
7526 "\n" +
7527 " if (alignment < MINSIZE) alignment = MINSIZE;\n" +
7528 "\n" +
7529 " /* Make sure alignment is power of 2 (in case MINSIZE is not). */\n" +
7530 " if ((alignment & (alignment - 1)) != 0) {\n" +
7531 " size_t a = MALLOC_ALIGNMENT * 2;\n" +
7532 " while ((CHUNK_SIZE_T)a < (CHUNK_SIZE_T)alignment) a <<= 1;\n" +
7533 " alignment = a;\n" +
7534 " }\n" +
7535 "\n" +
7536 " checked_request2size(bytes, nb);\n" +
7537 "\n" +
7538 " /*\n" +
7539 " Strategy: find a spot within that chunk that meets the alignment\n" +
7540 " request, and then possibly free the leading and trailing space.\n" +
7541 " */\n" +
7542 "\n" +
7543 "\n" +
7544 " /* Call malloc with worst case padding to hit alignment. */\n" +
7545 "\n" +
7546 " m = (char*)(mALLOc(nb + alignment + MINSIZE));\n" +
7547 "\n" +
7548 " if (m == 0) return 0; /* propagate failure */\n" +
7549 "\n" +
7550 " p = mem2chunk(m);\n" +
7551 "\n" +
7552 " if ((((PTR_UINT)(m)) % alignment) != 0) { /* misaligned */\n" +
7553 "\n" +
7554 " /*\n" +
7555 " Find an aligned spot inside chunk. Since we need to give back\n" +
7556 " leading space in a chunk of at least MINSIZE, if the first\n" +
7557 " calculation places us at a spot with less than MINSIZE leader,\n" +
7558 " we can move to the next aligned spot -- we've allocated enough\n" +
7559 " total room so that this is always possible.\n" +
7560 " */\n" +
7561 "\n" +
7562 " brk = (char*)mem2chunk((PTR_UINT)(((PTR_UINT)(m + alignment - 1)) &\n" +
7563 " -((signed long) alignment)));\n" +
7564 " if ((CHUNK_SIZE_T)(brk - (char*)(p)) < MINSIZE)\n" +
7565 " brk += alignment;\n" +
7566 "\n" +
7567 " newp = (mchunkptr)brk;\n" +
7568 " leadsize = brk - (char*)(p);\n" +
7569 " newsize = chunksize(p) - leadsize;\n" +
7570 "\n" +
7571 " /* For mmapped chunks, just adjust offset */\n" +
7572 " if (chunk_is_mmapped(p)) {\n" +
7573 " newp->prev_size = p->prev_size + leadsize;\n" +
7574 " set_head(newp, newsize|IS_MMAPPED);\n" +
7575 " return chunk2mem(newp);\n" +
7576 " }\n" +
7577 "\n" +
7578 " /* Otherwise, give back leader, use the rest */\n" +
7579 " set_head(newp, newsize | PREV_INUSE);\n" +
7580 " set_inuse_bit_at_offset(newp, newsize);\n" +
7581 " set_head_size(p, leadsize);\n" +
7582 " fREe(chunk2mem(p));\n" +
7583 " p = newp;\n" +
7584 "\n" +
7585 " assert (newsize >= nb &&\n" +
7586 " (((PTR_UINT)(chunk2mem(p))) % alignment) == 0);\n" +
7587 " }\n" +
7588 "\n" +
7589 " /* Also give back spare room at the end */\n" +
7590 " if (!chunk_is_mmapped(p)) {\n" +
7591 " size = chunksize(p);\n" +
7592 " if ((CHUNK_SIZE_T)(size) > (CHUNK_SIZE_T)(nb + MINSIZE)) {\n" +
7593 " remainder_size = size - nb;\n" +
7594 " remainder = chunk_at_offset(p, nb);\n" +
7595 " set_head(remainder, remainder_size | PREV_INUSE);\n" +
7596 " set_head_size(p, nb);\n" +
7597 " fREe(chunk2mem(remainder));\n" +
7598 " }\n" +
7599 " }\n" +
7600 "\n" +
7601 " check_inuse_chunk(p);\n" +
7602 " return chunk2mem(p);\n" +
7603 "}\n" +
7604 "\n" +
7605 "/*\n" +
7606 " ------------------------------ calloc ------------------------------\n" +
7607 "*/\n" +
7608 "\n" +
7609 "#if __STD_C\n" +
7610 "Void_t* cALLOc(size_t n_elements, size_t elem_size)\n" +
7611 "#else\n" +
7612 "Void_t* cALLOc(n_elements, elem_size) size_t n_elements; size_t elem_size;\n" +
7613 "#endif\n" +
7614 "{\n" +
7615 " mchunkptr p;\n" +
7616 " CHUNK_SIZE_T clearsize;\n" +
7617 " CHUNK_SIZE_T nclears;\n" +
7618 " INTERNAL_SIZE_T* d;\n" +
7619 "\n") +
7621 " Void_t* mem = mALLOc(n_elements * elem_size);\n" +
7622 "\n" +
7623 " if (mem != 0) {\n" +
7624 " p = mem2chunk(mem);\n" +
7625 "\n" +
7626 " if (!chunk_is_mmapped(p))\n" +
7627 " {\n" +
7628 " /*\n" +
7629 " Unroll clear of <= 36 bytes (72 if 8byte sizes)\n" +
7630 " We know that contents have an odd number of\n" +
7631 " INTERNAL_SIZE_T-sized words; minimally 3.\n" +
7632 " */\n" +
7633 "\n" +
7634 " d = (INTERNAL_SIZE_T*)mem;\n" +
7635 " clearsize = chunksize(p) - SIZE_SZ;\n" +
7636 " nclears = clearsize / sizeof(INTERNAL_SIZE_T);\n" +
7637 " assert(nclears >= 3);\n" +
7638 "\n" +
7639 " if (nclears > 9)\n" +
7640 " MALLOC_ZERO(d, clearsize);\n" +
7641 "\n" +
7642 " else {\n" +
7643 " *(d+0) = 0;\n" +
7644 " *(d+1) = 0;\n" +
7645 " *(d+2) = 0;\n" +
7646 " if (nclears > 4) {\n" +
7647 " *(d+3) = 0;\n" +
7648 " *(d+4) = 0;\n" +
7649 " if (nclears > 6) {\n" +
7650 " *(d+5) = 0;\n" +
7651 " *(d+6) = 0;\n" +
7652 " if (nclears > 8) {\n" +
7653 " *(d+7) = 0;\n" +
7654 " *(d+8) = 0;\n" +
7655 " }\n" +
7656 " }\n" +
7657 " }\n" +
7658 " }\n" +
7659 " }\n" +
7660 "#if ! MMAP_CLEARS\n" +
7661 " else\n" +
7662 " {\n" +
7663 " d = (INTERNAL_SIZE_T*)mem;\n" +
7664 " /*\n" +
7665 " Note the additional SIZE_SZ\n" +
7666 " */\n" +
7667 " clearsize = chunksize(p) - 2*SIZE_SZ;\n" +
7668 " MALLOC_ZERO(d, clearsize);\n" +
7669 " }\n" +
7670 "#endif\n" +
7671 " }\n" +
7672 " return mem;\n" +
7673 "}\n" +
7674 "\n" +
7675 "/*\n" +
7676 " ------------------------------ cfree ------------------------------\n" +
7677 "*/\n" +
7678 "\n" +
7679 "#if __STD_C\n" +
7680 "void cFREe(Void_t *mem)\n" +
7681 "#else\n" +
7682 "void cFREe(mem) Void_t *mem;\n" +
7683 "#endif\n" +
7684 "{\n" +
7685 " fREe(mem);\n" +
7686 "}\n" +
7687 "\n" +
7688 "/*\n" +
7689 " ------------------------- independent_calloc -------------------------\n" +
7690 "*/\n" +
7691 "\n" +
7692 "#if __STD_C\n" +
7693 "Void_t** iCALLOc(size_t n_elements, size_t elem_size, Void_t* chunks[])\n" +
7694 "#else\n" +
7695 … iCALLOc(n_elements, elem_size, chunks) size_t n_elements; size_t elem_size; Void_t* chunks[];\n" +
7696 "#endif\n" +
7697 "{\n" +
7698 " size_t sz = elem_size; /* serves as 1-element array */\n" +
7699 " /* opts arg of 3 means all elements are same size, and should be cleared */\n" +
7700 " return iALLOc(n_elements, &sz, 3, chunks);\n" +
7701 "}\n" +
7702 "\n" +
7703 "/*\n" +
7704 " ------------------------- independent_comalloc -------------------------\n" +
7705 "*/\n" +
7706 "\n" +
7707 "#if __STD_C\n" +
7708 "Void_t** iCOMALLOc(size_t n_elements, size_t sizes[], Void_t* chunks[])\n" +
7709 "#else\n" +
7710 …_t** iCOMALLOc(n_elements, sizes, chunks) size_t n_elements; size_t sizes[]; Void_t* chunks[];\n" +
7711 "#endif\n" +
7712 "{\n" +
7713 " return iALLOc(n_elements, sizes, 0, chunks);\n" +
7714 "}\n" +
7715 "\n" +
7716 "\n" +
7717 "/*\n" +
7718 " ------------------------------ ialloc ------------------------------\n" +
7719 " ialloc provides common support for independent_X routines, handling all of\n" +
7720 " the combinations that can result.\n" +
7721 "\n" +
7722 " The opts arg has:\n" +
7723 " bit 0 set if all elements are same size (using sizes[0])\n" +
7724 " bit 1 set if elements should be zeroed\n" +
7725 "*/\n" +
7726 "\n" +
7727 "\n" +
7728 "#if __STD_C\n" +
7729 "static Void_t** iALLOc(size_t n_elements,\n" +
7730 " size_t* sizes,\n" +
7731 " int opts,\n" +
7732 " Void_t* chunks[])\n" +
7733 "#else\n" +
7734 …n_elements, sizes, opts, chunks) size_t n_elements; size_t* sizes; int opts; Void_t* chunks[];\n" +
7735 "#endif\n" +
7736 "{\n" +
7737 " mstate av = get_malloc_state();\n" +
7738 " INTERNAL_SIZE_T element_size; /* chunksize of each element, if all same */\n" +
7739 " INTERNAL_SIZE_T contents_size; /* total size of elements */\n" +
7740 " INTERNAL_SIZE_T array_size; /* request size of pointer array */\n" +
7741 " Void_t* mem; /* malloced aggregate space */\n" +
7742 " mchunkptr p; /* corresponding chunk */\n" +
7743 " INTERNAL_SIZE_T remainder_size; /* remaining bytes while splitting */\n" +
7744 " Void_t** marray; /* either \"chunks\" or malloced ptr array */\n" +
7745 " mchunkptr array_chunk; /* chunk for malloced ptr array */\n" +
7746 " int mmx; /* to disable mmap */\n" +
7747 " INTERNAL_SIZE_T size;\n" +
7748 " size_t i;\n" +
7749 "\n" +
7750 " /* Ensure initialization */\n" +
7751 " if (av->max_fast == 0) malloc_consolidate(av);\n" +
7752 "\n" +
7753 " /* compute array length, if needed */\n" +
7754 " if (chunks != 0) {\n" +
7755 " if (n_elements == 0)\n" +
7756 " return chunks; /* nothing to do */\n" +
7757 " marray = chunks;\n" +
7758 " array_size = 0;\n" +
7759 " }\n" +
7760 " else {\n" +
7761 " /* if empty req, must still return chunk representing empty array */\n" +
7762 " if (n_elements == 0)\n" +
7763 " return (Void_t**) mALLOc(0);\n" +
7764 " marray = 0;\n" +
7765 " array_size = request2size(n_elements * (sizeof(Void_t*)));\n" +
7766 " }\n" +
7767 "\n" +
7768 " /* compute total element size */\n" +
7769 " if (opts & 0x1) { /* all-same-size */\n" +
7770 " element_size = request2size(*sizes);\n" +
7771 " contents_size = n_elements * element_size;\n" +
7772 " }\n" +
7773 " else { /* add up all the sizes */\n" +
7774 " element_size = 0;\n" +
7775 " contents_size = 0;\n" +
7776 " for (i = 0; i != n_elements; ++i)\n" +
7777 " contents_size += request2size(sizes[i]);\n" +
7778 " }\n" +
7779 "\n") +
7781 " /* subtract out alignment bytes from total to minimize overallocation */\n" +
7782 " size = contents_size + array_size - MALLOC_ALIGN_MASK;\n" +
7783 "\n" +
7784 " /*\n" +
7785 " Allocate the aggregate chunk.\n" +
7786 " But first disable mmap so malloc won't use it, since\n" +
7787 " we would not be able to later free/realloc space internal\n" +
7788 " to a segregated mmap region.\n" +
7789 " */\n" +
7790 " mmx = av->n_mmaps_max; /* disable mmap */\n" +
7791 " av->n_mmaps_max = 0;\n" +
7792 " mem = mALLOc(size);\n" +
7793 " av->n_mmaps_max = mmx; /* reset mmap */\n" +
7794 " if (mem == 0)\n" +
7795 " return 0;\n" +
7796 "\n" +
7797 " p = mem2chunk(mem);\n" +
7798 " assert(!chunk_is_mmapped(p));\n" +
7799 " remainder_size = chunksize(p);\n" +
7800 "\n" +
7801 " if (opts & 0x2) { /* optionally clear the elements */\n" +
7802 " MALLOC_ZERO(mem, remainder_size - SIZE_SZ - array_size);\n" +
7803 " }\n" +
7804 "\n" +
7805 " /* If not provided, allocate the pointer array as final part of chunk */\n" +
7806 " if (marray == 0) {\n" +
7807 " array_chunk = chunk_at_offset(p, contents_size);\n" +
7808 " marray = (Void_t**) (chunk2mem(array_chunk));\n" +
7809 " set_head(array_chunk, (remainder_size - contents_size) | PREV_INUSE);\n" +
7810 " remainder_size = contents_size;\n" +
7811 " }\n" +
7812 "\n" +
7813 " /* split out elements */\n" +
7814 " for (i = 0; ; ++i) {\n" +
7815 " marray[i] = chunk2mem(p);\n" +
7816 " if (i != n_elements-1) {\n" +
7817 " if (element_size != 0)\n" +
7818 " size = element_size;\n" +
7819 " else\n" +
7820 " size = request2size(sizes[i]);\n" +
7821 " remainder_size -= size;\n" +
7822 " set_head(p, size | PREV_INUSE);\n" +
7823 " p = chunk_at_offset(p, size);\n" +
7824 " }\n" +
7825 " else { /* the final element absorbs any overallocation slop */\n" +
7826 " set_head(p, remainder_size | PREV_INUSE);\n" +
7827 " break;\n" +
7828 " }\n" +
7829 " }\n" +
7830 "\n" +
7831 "#if DEBUG\n" +
7832 " if (marray != chunks) {\n" +
7833 " /* final element must have exactly exhausted chunk */\n" +
7834 " if (element_size != 0)\n" +
7835 " assert(remainder_size == element_size);\n" +
7836 " else\n" +
7837 " assert(remainder_size == request2size(sizes[i]));\n" +
7838 " check_inuse_chunk(mem2chunk(marray));\n" +
7839 " }\n" +
7840 "\n" +
7841 " for (i = 0; i != n_elements; ++i)\n" +
7842 " check_inuse_chunk(mem2chunk(marray[i]));\n" +
7843 "#endif\n" +
7844 "\n" +
7845 " return marray;\n" +
7846 "}\n" +
7847 "\n" +
7848 "\n" +
7849 "/*\n" +
7850 " ------------------------------ valloc ------------------------------\n" +
7851 "*/\n" +
7852 "\n" +
7853 "#if __STD_C\n" +
7854 "Void_t* vALLOc(size_t bytes)\n" +
7855 "#else\n" +
7856 "Void_t* vALLOc(bytes) size_t bytes;\n" +
7857 "#endif\n" +
7858 "{\n" +
7859 " /* Ensure initialization */\n" +
7860 " mstate av = get_malloc_state();\n" +
7861 " if (av->max_fast == 0) malloc_consolidate(av);\n" +
7862 " return mEMALIGn(av->pagesize, bytes);\n" +
7863 "}\n" +
7864 "\n" +
7865 "/*\n" +
7866 " ------------------------------ pvalloc ------------------------------\n" +
7867 "*/\n" +
7868 "\n" +
7869 "\n" +
7870 "#if __STD_C\n" +
7871 "Void_t* pVALLOc(size_t bytes)\n" +
7872 "#else\n" +
7873 "Void_t* pVALLOc(bytes) size_t bytes;\n" +
7874 "#endif\n" +
7875 "{\n" +
7876 " mstate av = get_malloc_state();\n" +
7877 " size_t pagesz;\n" +
7878 "\n" +
7879 " /* Ensure initialization */\n" +
7880 " if (av->max_fast == 0) malloc_consolidate(av);\n" +
7881 " pagesz = av->pagesize;\n" +
7882 " return mEMALIGn(pagesz, (bytes + pagesz - 1) & ~(pagesz - 1));\n" +
7883 "}\n" +
7884 "\n" +
7885 "\n" +
7886 "/*\n" +
7887 " ------------------------------ malloc_trim ------------------------------\n" +
7888 "*/\n" +
7889 "\n" +
7890 "#if __STD_C\n" +
7891 "int mTRIm(size_t pad)\n" +
7892 "#else\n" +
7893 "int mTRIm(pad) size_t pad;\n" +
7894 "#endif\n" +
7895 "{\n" +
7896 " mstate av = get_malloc_state();\n" +
7897 " /* Ensure initialization/consolidation */\n" +
7898 " malloc_consolidate(av);\n" +
7899 "\n" +
7900 "#ifndef MORECORE_CANNOT_TRIM\n" +
7901 " return sYSTRIm(pad, av);\n" +
7902 "#else\n" +
7903 " return 0;\n" +
7904 "#endif\n" +
7905 "}\n" +
7906 "\n" +
7907 "\n" +
7908 "/*\n" +
7909 " ------------------------- malloc_usable_size -------------------------\n" +
7910 "*/\n" +
7911 "\n" +
7912 "#if __STD_C\n" +
7913 "size_t mUSABLe(Void_t* mem)\n" +
7914 "#else\n" +
7915 "size_t mUSABLe(mem) Void_t* mem;\n" +
7916 "#endif\n" +
7917 "{\n" +
7918 " mchunkptr p;\n" +
7919 " if (mem != 0) {\n" +
7920 " p = mem2chunk(mem);\n" +
7921 " if (chunk_is_mmapped(p))\n" +
7922 " return chunksize(p) - 2*SIZE_SZ;\n" +
7923 " else if (inuse(p))\n" +
7924 " return chunksize(p) - SIZE_SZ;\n" +
7925 " }\n" +
7926 " return 0;\n" +
7927 "}\n" +
7928 "\n" +
7929 "/*\n" +
7930 " ------------------------------ mallinfo ------------------------------\n" +
7931 "*/\n" +
7932 "\n") +
7934 "struct mallinfo mALLINFo()\n" +
7935 "{\n" +
7936 " mstate av = get_malloc_state();\n" +
7937 " struct mallinfo mi;\n" +
7938 " unsigned int i;\n" +
7939 " mbinptr b;\n" +
7940 " mchunkptr p;\n" +
7941 " INTERNAL_SIZE_T avail;\n" +
7942 " INTERNAL_SIZE_T fastavail;\n" +
7943 " int nblocks;\n" +
7944 " int nfastblocks;\n" +
7945 "\n" +
7946 " /* Ensure initialization */\n" +
7947 " if (av->top == 0) malloc_consolidate(av);\n" +
7948 "\n" +
7949 " check_malloc_state();\n" +
7950 "\n" +
7951 " /* Account for top */\n" +
7952 " avail = chunksize(av->top);\n" +
7953 " nblocks = 1; /* top always exists */\n" +
7954 "\n" +
7955 " /* traverse fastbins */\n" +
7956 " nfastblocks = 0;\n" +
7957 " fastavail = 0;\n" +
7958 "\n" +
7959 " for (i = 0; i < NFASTBINS; ++i) {\n" +
7960 " for (p = av->fastbins[i]; p != 0; p = p->fd) {\n" +
7961 " ++nfastblocks;\n" +
7962 " fastavail += chunksize(p);\n" +
7963 " }\n" +
7964 " }\n" +
7965 "\n" +
7966 " avail += fastavail;\n" +
7967 "\n" +
7968 " /* traverse regular bins */\n" +
7969 " for (i = 1; i < NBINS; ++i) {\n" +
7970 " b = bin_at(av, i);\n" +
7971 " for (p = last(b); p != b; p = p->bk) {\n" +
7972 " ++nblocks;\n" +
7973 " avail += chunksize(p);\n" +
7974 " }\n" +
7975 " }\n" +
7976 "\n" +
7977 " mi.smblks = nfastblocks;\n" +
7978 " mi.ordblks = nblocks;\n" +
7979 " mi.fordblks = avail;\n" +
7980 " mi.uordblks = av->sbrked_mem - avail;\n" +
7981 " mi.arena = av->sbrked_mem;\n" +
7982 " mi.hblks = av->n_mmaps;\n" +
7983 " mi.hblkhd = av->mmapped_mem;\n" +
7984 " mi.fsmblks = fastavail;\n" +
7985 " mi.keepcost = chunksize(av->top);\n" +
7986 " mi.usmblks = av->max_total_mem;\n" +
7987 " return mi;\n" +
7988 "}\n" +
7989 "\n" +
7990 "/*\n" +
7991 " ------------------------------ malloc_stats ------------------------------\n" +
7992 "*/\n" +
7993 "\n" +
7994 "void mSTATs()\n" +
7995 "{\n" +
7996 " struct mallinfo mi = mALLINFo();\n" +
7997 "\n" +
7998 "#ifdef WIN32\n" +
7999 " {\n" +
8000 " CHUNK_SIZE_T free, reserved, committed;\n" +
8001 " vminfo (&free, &reserved, &committed);\n" +
8002 " fprintf(stderr, \"free bytes = %10lu\\n\",\n" +
8003 " free);\n" +
8004 " fprintf(stderr, \"reserved bytes = %10lu\\n\",\n" +
8005 " reserved);\n" +
8006 " fprintf(stderr, \"committed bytes = %10lu\\n\",\n" +
8007 " committed);\n" +
8008 " }\n" +
8009 "#endif\n" +
8010 "\n" +
8011 "\n" +
8012 " fprintf(stderr, \"max system bytes = %10lu\\n\",\n" +
8013 " (CHUNK_SIZE_T)(mi.usmblks));\n" +
8014 " fprintf(stderr, \"system bytes = %10lu\\n\",\n" +
8015 " (CHUNK_SIZE_T)(mi.arena + mi.hblkhd));\n" +
8016 " fprintf(stderr, \"in use bytes = %10lu\\n\",\n" +
8017 " (CHUNK_SIZE_T)(mi.uordblks + mi.hblkhd));\n" +
8018 "\n" +
8019 "#ifdef WIN32\n" +
8020 " {\n" +
8021 " CHUNK_SIZE_T kernel, user;\n" +
8022 " if (cpuinfo (TRUE, &kernel, &user)) {\n" +
8023 " fprintf(stderr, \"kernel ms = %10lu\\n\",\n" +
8024 " kernel);\n" +
8025 " fprintf(stderr, \"user ms = %10lu\\n\",\n" +
8026 " user);\n" +
8027 " }\n" +
8028 " }\n" +
8029 "#endif\n" +
8030 "}\n" +
8031 "\n" +
8032 "\n" +
8033 "/*\n" +
8034 " ------------------------------ mallopt ------------------------------\n" +
8035 "*/\n" +
8036 "\n" +
8037 "#if __STD_C\n" +
8038 "int mALLOPt(int param_number, int value)\n" +
8039 "#else\n" +
8040 "int mALLOPt(param_number, value) int param_number; int value;\n" +
8041 "#endif\n" +
8042 "{\n" +
8043 " mstate av = get_malloc_state();\n" +
8044 " /* Ensure initialization/consolidation */\n" +
8045 " malloc_consolidate(av);\n" +
8046 "\n" +
8047 " switch(param_number) {\n" +
8048 " case M_MXFAST:\n" +
8049 " if (value >= 0 && value <= MAX_FAST_SIZE) {\n" +
8050 " set_max_fast(av, value);\n" +
8051 " return 1;\n" +
8052 " }\n" +
8053 " else\n" +
8054 " return 0;\n" +
8055 "\n" +
8056 " case M_TRIM_THRESHOLD:\n" +
8057 " av->trim_threshold = value;\n" +
8058 " return 1;\n" +
8059 "\n" +
8060 " case M_TOP_PAD:\n" +
8061 " av->top_pad = value;\n" +
8062 " return 1;\n" +
8063 "\n" +
8064 " case M_MMAP_THRESHOLD:\n" +
8065 " av->mmap_threshold = value;\n" +
8066 " return 1;\n" +
8067 "\n" +
8068 " case M_MMAP_MAX:\n" +
8069 "#if !HAVE_MMAP\n" +
8070 " if (value != 0)\n" +
8071 " return 0;\n" +
8072 "#endif\n" +
8073 " av->n_mmaps_max = value;\n" +
8074 " return 1;\n" +
8075 "\n" +
8076 " default:\n" +
8077 " return 0;\n" +
8078 " }\n" +
8079 "}\n" +
8080 "\n" +
8081 "\n" +
8082 "/*\n" +
8083 " -------------------- Alternative MORECORE functions --------------------\n" +
8084 "*/\n" +
8085 "\n") +
8087 "\n" +
8088 "/*\n" +
8089 " General Requirements for MORECORE.\n" +
8090 "\n" +
8091 " The MORECORE function must have the following properties:\n" +
8092 "\n" +
8093 " If MORECORE_CONTIGUOUS is false:\n" +
8094 "\n" +
8095 " * MORECORE must allocate in multiples of pagesize. It will\n" +
8096 " only be called with arguments that are multiples of pagesize.\n" +
8097 "\n" +
8098 " * MORECORE(0) must return an address that is at least\n" +
8099 " MALLOC_ALIGNMENT aligned. (Page-aligning always suffices.)\n" +
8100 "\n" +
8101 " else (i.e. If MORECORE_CONTIGUOUS is true):\n" +
8102 "\n" +
8103 " * Consecutive calls to MORECORE with positive arguments\n" +
8104 " return increasing addresses, indicating that space has been\n" +
8105 " contiguously extended.\n" +
8106 "\n" +
8107 " * MORECORE need not allocate in multiples of pagesize.\n" +
8108 " Calls to MORECORE need not have args of multiples of pagesize.\n" +
8109 "\n" +
8110 " * MORECORE need not page-align.\n" +
8111 "\n" +
8112 " In either case:\n" +
8113 "\n" +
8114 " * MORECORE may allocate more memory than requested. (Or even less,\n" +
8115 " but this will generally result in a malloc failure.)\n" +
8116 "\n" +
8117 " * MORECORE must not allocate memory when given argument zero, but\n" +
8118 " instead return one past the end address of memory from previous\n" +
8119 " nonzero call. This malloc does NOT call MORECORE(0)\n" +
8120 " until at least one call with positive arguments is made, so\n" +
8121 " the initial value returned is not important.\n" +
8122 "\n" +
8123 " * Even though consecutive calls to MORECORE need not return contiguous\n" +
8124 " addresses, it must be OK for malloc'ed chunks to span multiple\n" +
8125 " regions in those cases where they do happen to be contiguous.\n" +
8126 "\n" +
8127 " * MORECORE need not handle negative arguments -- it may instead\n" +
8128 " just return MORECORE_FAILURE when given negative arguments.\n" +
8129 " Negative arguments are always multiples of pagesize. MORECORE\n" +
8130 " must not misinterpret negative args as large positive unsigned\n" +
8131 " args. You can suppress all such calls from even occurring by defining\n" +
8132 " MORECORE_CANNOT_TRIM,\n" +
8133 "\n" +
8134 " There is some variation across systems about the type of the\n" +
8135 " argument to sbrk/MORECORE. If size_t is unsigned, then it cannot\n" +
8136 " actually be size_t, because sbrk supports negative args, so it is\n" +
8137 " normally the signed type of the same width as size_t (sometimes\n" +
8138 " declared as \"intptr_t\", and sometimes \"ptrdiff_t\"). It doesn't much\n" +
8139 " matter though. Internally, we use \"long\" as arguments, which should\n" +
8140 " work across all reasonable possibilities.\n" +
8141 "\n" +
8142 " Additionally, if MORECORE ever returns failure for a positive\n" +
8143 " request, and HAVE_MMAP is true, then mmap is used as a noncontiguous\n" +
8144 " system allocator. This is a useful backup strategy for systems with\n" +
8145 " holes in address spaces -- in this case sbrk cannot contiguously\n" +
8146 " expand the heap, but mmap may be able to map noncontiguous space.\n" +
8147 "\n" +
8148 " If you'd like mmap to ALWAYS be used, you can define MORECORE to be\n" +
8149 " a function that always returns MORECORE_FAILURE.\n" +
8150 "\n" +
8151 " Malloc only has limited ability to detect failures of MORECORE\n" +
8152 " to supply contiguous space when it says it can. In particular,\n" +
8153 " multithreaded programs that do not use locks may result in\n" +
8154 " rece conditions across calls to MORECORE that result in gaps\n" +
8155 " that cannot be detected as such, and subsequent corruption.\n" +
8156 "\n" +
8157 " If you are using this malloc with something other than sbrk (or its\n" +
8158 " emulation) to supply memory regions, you probably want to set\n" +
8159 " MORECORE_CONTIGUOUS as false. As an example, here is a custom\n" +
8160 " allocator kindly contributed for pre-OSX macOS. It uses virtually\n" +
8161 " but not necessarily physically contiguous non-paged memory (locked\n" +
8162 " in, present and won't get swapped out). You can use it by\n" +
8163 " uncommenting this section, adding some #includes, and setting up the\n" +
8164 " appropriate defines above:\n" +
8165 "\n" +
8166 " #define MORECORE osMoreCore\n" +
8167 " #define MORECORE_CONTIGUOUS 0\n" +
8168 "\n" +
8169 " There is also a shutdown routine that should somehow be called for\n" +
8170 " cleanup upon program exit.\n" +
8171 "\n" +
8172 " #define MAX_POOL_ENTRIES 100\n" +
8173 " #define MINIMUM_MORECORE_SIZE (64 * 1024)\n" +
8174 " static int next_os_pool;\n" +
8175 " void *our_os_pools[MAX_POOL_ENTRIES];\n" +
8176 "\n" +
8177 " void *osMoreCore(int size)\n" +
8178 " {\n" +
8179 " void *ptr = 0;\n" +
8180 " static void *sbrk_top = 0;\n" +
8181 "\n" +
8182 " if (size > 0)\n" +
8183 " {\n" +
8184 " if (size < MINIMUM_MORECORE_SIZE)\n" +
8185 " size = MINIMUM_MORECORE_SIZE;\n" +
8186 " if (CurrentExecutionLevel() == kTaskLevel)\n" +
8187 " ptr = PoolAllocateResident(size + RM_PAGE_SIZE, 0);\n" +
8188 " if (ptr == 0)\n" +
8189 " {\n" +
8190 " return (void *) MORECORE_FAILURE;\n" +
8191 " }\n" +
8192 " // save ptrs so they can be freed during cleanup\n" +
8193 " our_os_pools[next_os_pool] = ptr;\n" +
8194 " next_os_pool++;\n" +
8195 " ptr = (void *) ((((CHUNK_SIZE_T) ptr) + RM_PAGE_MASK) & ~RM_PAGE_MASK);\n" +
8196 " sbrk_top = (char *) ptr + size;\n" +
8197 " return ptr;\n" +
8198 " }\n" +
8199 " else if (size < 0)\n" +
8200 " {\n" +
8201 " // we don't currently support shrink behavior\n" +
8202 " return (void *) MORECORE_FAILURE;\n" +
8203 " }\n" +
8204 " else\n" +
8205 " {\n" +
8206 " return sbrk_top;\n" +
8207 " }\n" +
8208 " }\n" +
8209 "\n" +
8210 " // cleanup any allocated memory pools\n" +
8211 " // called as last thing before shutting down driver\n" +
8212 "\n" +
8213 " void osCleanupMem(void)\n" +
8214 " {\n" +
8215 " void **ptr;\n" +
8216 "\n" +
8217 " for (ptr = our_os_pools; ptr < &our_os_pools[MAX_POOL_ENTRIES]; ptr++)\n" +
8218 " if (*ptr)\n" +
8219 " {\n" +
8220 " PoolDeallocate(*ptr);\n" +
8221 " *ptr = 0;\n" +
8222 " }\n" +
8223 " }\n" +
8224 "\n" +
8225 "*/\n" +
8226 "\n" +
8227 "\n" +
8228 "/*\n" +
8229 " --------------------------------------------------------------\n" +
8230 "\n" +
8231 " Emulation of sbrk for win32.\n" +
8232 " Donated by J. Walter <Walter@GeNeSys-e.de>.\n" +
8233 " For additional information about this code, and malloc on Win32, see\n" +
8234 " http://www.genesys-e.de/jwalter/\n" +
8235 "*/\n" +
8236 "\n" +
8237 "\n") +
8239 "#ifdef WIN32\n" +
8240 "\n" +
8241 "#ifdef _DEBUG\n" +
8242 "/* #define TRACE */\n" +
8243 "#endif\n" +
8244 "\n" +
8245 "/* Support for USE_MALLOC_LOCK */\n" +
8246 "#ifdef USE_MALLOC_LOCK\n" +
8247 "\n" +
8248 "/* Wait for spin lock */\n" +
8249 "static int slwait (int *sl) {\n" +
8250 " while (InterlockedCompareExchange ((void **) sl, (void *) 1, (void *) 0) != 0)\n" +
8251 " Sleep (0);\n" +
8252 " return 0;\n" +
8253 "}\n" +
8254 "\n" +
8255 "/* Release spin lock */\n" +
8256 "static int slrelease (int *sl) {\n" +
8257 " InterlockedExchange (sl, 0);\n" +
8258 " return 0;\n" +
8259 "}\n" +
8260 "\n" +
8261 "#ifdef NEEDED\n" +
8262 "/* Spin lock for emulation code */\n" +
8263 "static int g_sl;\n" +
8264 "#endif\n" +
8265 "\n" +
8266 "#endif /* USE_MALLOC_LOCK */\n" +
8267 "\n" +
8268 "/* getpagesize for windows */\n" +
8269 "static long getpagesize (void) {\n" +
8270 " static long g_pagesize = 0;\n" +
8271 " if (! g_pagesize) {\n" +
8272 " SYSTEM_INFO system_info;\n" +
8273 " GetSystemInfo (&system_info);\n" +
8274 " g_pagesize = system_info.dwPageSize;\n" +
8275 " }\n" +
8276 " return g_pagesize;\n" +
8277 "}\n" +
8278 "static long getregionsize (void) {\n" +
8279 " static long g_regionsize = 0;\n" +
8280 " if (! g_regionsize) {\n" +
8281 " SYSTEM_INFO system_info;\n" +
8282 " GetSystemInfo (&system_info);\n" +
8283 " g_regionsize = system_info.dwAllocationGranularity;\n" +
8284 " }\n" +
8285 " return g_regionsize;\n" +
8286 "}\n" +
8287 "\n" +
8288 "/* A region list entry */\n" +
8289 "typedef struct _region_list_entry {\n" +
8290 " void *top_allocated;\n" +
8291 " void *top_committed;\n" +
8292 " void *top_reserved;\n" +
8293 " long reserve_size;\n" +
8294 " struct _region_list_entry *previous;\n" +
8295 "} region_list_entry;\n" +
8296 "\n" +
8297 "/* Allocate and link a region entry in the region list */\n" +
8298 …ic int region_list_append (region_list_entry **last, void *base_reserved, long reserve_size) {\n" +
8299 " region_list_entry *next = HeapAlloc (GetProcessHeap (), 0, sizeof (region_list_entry));\n" +
8300 " if (! next)\n" +
8301 " return FALSE;\n" +
8302 " next->top_allocated = (char *) base_reserved;\n" +
8303 " next->top_committed = (char *) base_reserved;\n" +
8304 " next->top_reserved = (char *) base_reserved + reserve_size;\n" +
8305 " next->reserve_size = reserve_size;\n" +
8306 " next->previous = *last;\n" +
8307 " *last = next;\n" +
8308 " return TRUE;\n" +
8309 "}\n" +
8310 "/* Free and unlink the last region entry from the region list */\n" +
8311 "static int region_list_remove (region_list_entry **last) {\n" +
8312 " region_list_entry *previous = (*last)->previous;\n" +
8313 " if (! HeapFree (GetProcessHeap (), sizeof (region_list_entry), *last))\n" +
8314 " return FALSE;\n" +
8315 " *last = previous;\n" +
8316 " return TRUE;\n" +
8317 "}\n" +
8318 "\n" +
8319 "#define CEIL(size,to) (((size)+(to)-1)&~((to)-1))\n" +
8320 "#define FLOOR(size,to) ((size)&~((to)-1))\n" +
8321 "\n" +
8322 "#define SBRK_SCALE 0\n" +
8323 "/* #define SBRK_SCALE 1 */\n" +
8324 "/* #define SBRK_SCALE 2 */\n" +
8325 "/* #define SBRK_SCALE 4 */\n" +
8326 "\n" +
8327 "/* sbrk for windows */\n" +
8328 "static void *sbrk (long size) {\n" +
8329 " static long g_pagesize, g_my_pagesize;\n" +
8330 " static long g_regionsize, g_my_regionsize;\n" +
8331 " static region_list_entry *g_last;\n" +
8332 " void *result = (void *) MORECORE_FAILURE;\n" +
8333 "#ifdef TRACE\n" +
8334 " printf (\"sbrk %d\\n\", size);\n" +
8335 "#endif\n" +
8336 "#if defined (USE_MALLOC_LOCK) && defined (NEEDED)\n" +
8337 " /* Wait for spin lock */\n" +
8338 " slwait (&g_sl);\n" +
8339 "#endif\n" +
8340 " /* First time initialization */\n" +
8341 " if (! g_pagesize) {\n" +
8342 " g_pagesize = getpagesize ();\n" +
8343 " g_my_pagesize = g_pagesize << SBRK_SCALE;\n" +
8344 " }\n" +
8345 " if (! g_regionsize) {\n" +
8346 " g_regionsize = getregionsize ();\n" +
8347 " g_my_regionsize = g_regionsize << SBRK_SCALE;\n" +
8348 " }\n" +
8349 " if (! g_last) {\n" +
8350 " if (! region_list_append (&g_last, 0, 0))\n" +
8351 " goto sbrk_exit;\n" +
8352 " }\n" +
8353 " /* Assert invariants */\n" +
8354 " assert (g_last);\n" +
8355 …ert ((char *) g_last->top_reserved - g_last->reserve_size <= (char *) g_last->top_allocated &&\n" +
8356 " g_last->top_allocated <= g_last->top_committed);\n" +
8357 …ert ((char *) g_last->top_reserved - g_last->reserve_size <= (char *) g_last->top_committed &&\n" +
8358 " g_last->top_committed <= g_last->top_reserved &&\n" +
8359 " (unsigned) g_last->top_committed % g_pagesize == 0);\n" +
8360 " assert ((unsigned) g_last->top_reserved % g_regionsize == 0);\n" +
8361 " assert ((unsigned) g_last->reserve_size % g_regionsize == 0);\n" +
8362 " /* Allocation requested? */\n" +
8363 " if (size >= 0) {\n" +
8364 " /* Allocation size is the requested size */\n" +
8365 " long allocate_size = size;\n" +
8366 " /* Compute the size to commit */\n" +
8367 …g to_commit = (char *) g_last->top_allocated + allocate_size - (char *) g_last->top_committed;\n" +
8368 " /* Do we reach the commit limit? */\n" +
8369 " if (to_commit > 0) {\n" +
8370 " /* Round size to commit */\n" +
8371 " long commit_size = CEIL (to_commit, g_my_pagesize);\n" +
8372 " /* Compute the size to reserve */\n" +
8373 …ong to_reserve = (char *) g_last->top_committed + commit_size - (char *) g_last->top_reserved;\n" +
8374 " /* Do we reach the reserve limit? */\n" +
8375 " if (to_reserve > 0) {\n" +
8376 " /* Compute the remaining size to commit in the current region */\n" +
8377 … long remaining_commit_size = (char *) g_last->top_reserved - (char *) g_last->top_committed;\n" +
8378 " if (remaining_commit_size > 0) {\n" +
8379 " /* Assert preconditions */\n" +
8380 " assert ((unsigned) g_last->top_committed % g_pagesize == 0);\n" +
8381 … assert (0 < remaining_commit_size && remaining_commit_size % g_pagesize == 0); {\n" +
8382 " /* Commit this */\n" +
8383 … void *base_committed = VirtualAlloc (g_last->top_committed, remaining_commit_size,\n" +
8384 " MEM_COMMIT, PAGE_READWRITE);\n" +
8385 " /* Check returned pointer for consistency */\n" +
8386 " if (base_committed != g_last->top_committed)\n" +
8387 " goto sbrk_exit;\n") +
8389 " /* Assert postconditions */\n" +
8390 " assert ((unsigned) base_committed % g_pagesize == 0);\n" +
8391 "#ifdef TRACE\n" +
8392 " printf (\"Commit %p %d\\n\", base_committed, remaining_commit_size);\n" +
8393 "#endif\n" +
8394 " /* Adjust the regions commit top */\n" +
8395 " g_last->top_committed = (char *) base_committed + remaining_commit_size;\n…
8396 " }\n" +
8397 " } {\n" +
8398 " /* Now we are going to search and reserve. */\n" +
8399 " int contiguous = -1;\n" +
8400 " int found = FALSE;\n" +
8401 " MEMORY_BASIC_INFORMATION memory_info;\n" +
8402 " void *base_reserved;\n" +
8403 " long reserve_size;\n" +
8404 " do {\n" +
8405 " /* Assume contiguous memory */\n" +
8406 " contiguous = TRUE;\n" +
8407 " /* Round size to reserve */\n" +
8408 " reserve_size = CEIL (to_reserve, g_my_regionsize);\n" +
8409 " /* Start with the current region's top */\n" +
8410 " memory_info.BaseAddress = g_last->top_reserved;\n" +
8411 " /* Assert preconditions */\n" +
8412 " assert ((unsigned) memory_info.BaseAddress % g_pagesize == 0);\n" +
8413 " assert (0 < reserve_size && reserve_size % g_regionsize == 0);\n" +
8414 … while (VirtualQuery (memory_info.BaseAddress, &memory_info, sizeof (memory_info))) {\n" +
8415 " /* Assert postconditions */\n" +
8416 " assert ((unsigned) memory_info.BaseAddress % g_pagesize == 0);\n" +
8417 "#ifdef TRACE\n" +
8418 … printf (\"Query %p %d %s\\n\", memory_info.BaseAddress, memory_info.RegionS…
8419 " memory_info.State == MEM_FREE ? \"FREE\":\n" +
8420 " (memory_info.State == MEM_RESERVE ? \"RESERVED\":\n" +
8421 " (memory_info.State == MEM_COMMIT ? \"COMMITTED\": \"?\")));\n…
8422 "#endif\n" +
8423 " /* Region is free, well aligned and big enough: we are done */\n" +
8424 " if (memory_info.State == MEM_FREE &&\n" +
8425 " (unsigned) memory_info.BaseAddress % g_regionsize == 0 &&\n" +
8426 " memory_info.RegionSize >= (unsigned) reserve_size) {\n" +
8427 " found = TRUE;\n" +
8428 " break;\n" +
8429 " }\n" +
8430 " /* From now on we can't get contiguous memory! */\n" +
8431 " contiguous = FALSE;\n" +
8432 " /* Recompute size to reserve */\n" +
8433 " reserve_size = CEIL (allocate_size, g_my_regionsize);\n" +
8434 … memory_info.BaseAddress = (char *) memory_info.BaseAddress + memory_info.RegionSize;\n" +
8435 " /* Assert preconditions */\n" +
8436 " assert ((unsigned) memory_info.BaseAddress % g_pagesize == 0);\n" +
8437 " assert (0 < reserve_size && reserve_size % g_regionsize == 0);\n" +
8438 " }\n" +
8439 " /* Search failed? */\n" +
8440 " if (! found)\n" +
8441 " goto sbrk_exit;\n" +
8442 " /* Assert preconditions */\n" +
8443 " assert ((unsigned) memory_info.BaseAddress % g_regionsize == 0);\n" +
8444 " assert (0 < reserve_size && reserve_size % g_regionsize == 0);\n" +
8445 " /* Try to reserve this */\n" +
8446 " base_reserved = VirtualAlloc (memory_info.BaseAddress, reserve_size,\n" +
8447 " MEM_RESERVE, PAGE_NOACCESS);\n" +
8448 " if (! base_reserved) {\n" +
8449 " int rc = GetLastError ();\n" +
8450 " if (rc != ERROR_INVALID_ADDRESS)\n" +
8451 " goto sbrk_exit;\n" +
8452 " }\n" +
8453 … /* A null pointer signals (hopefully) a race condition with another thread. */\n" +
8454 " /* In this case, we try again. */\n" +
8455 " } while (! base_reserved);\n" +
8456 " /* Check returned pointer for consistency */\n" +
8457 " if (memory_info.BaseAddress && base_reserved != memory_info.BaseAddress)\n" +
8458 " goto sbrk_exit;\n" +
8459 " /* Assert postconditions */\n" +
8460 " assert ((unsigned) base_reserved % g_regionsize == 0);\n" +
8461 "#ifdef TRACE\n" +
8462 " printf (\"Reserve %p %d\\n\", base_reserved, reserve_size);\n" +
8463 "#endif\n" +
8464 " /* Did we get contiguous memory? */\n" +
8465 " if (contiguous) {\n" +
8466 … long start_size = (char *) g_last->top_committed - (char *) g_last->top_allocated;\n" +
8467 " /* Adjust allocation size */\n" +
8468 " allocate_size -= start_size;\n" +
8469 " /* Adjust the regions allocation top */\n" +
8470 " g_last->top_allocated = g_last->top_committed;\n" +
8471 " /* Recompute the size to commit */\n" +
8472 … to_commit = (char *) g_last->top_allocated + allocate_size - (char *) g_last->top_committed;\n" +
8473 " /* Round size to commit */\n" +
8474 " commit_size = CEIL (to_commit, g_my_pagesize);\n" +
8475 " }\n" +
8476 " /* Append the new region to the list */\n" +
8477 " if (! region_list_append (&g_last, base_reserved, reserve_size))\n" +
8478 " goto sbrk_exit;\n" +
8479 " /* Didn't we get contiguous memory? */\n" +
8480 " if (! contiguous) {\n" +
8481 " /* Recompute the size to commit */\n" +
8482 … to_commit = (char *) g_last->top_allocated + allocate_size - (char *) g_last->top_committed;\n" +
8483 " /* Round size to commit */\n" +
8484 " commit_size = CEIL (to_commit, g_my_pagesize);\n" +
8485 " }\n" +
8486 " }\n" +
8487 " }\n" +
8488 " /* Assert preconditions */\n" +
8489 " assert ((unsigned) g_last->top_committed % g_pagesize == 0);\n" +
8490 " assert (0 < commit_size && commit_size % g_pagesize == 0); {\n" +
8491 " /* Commit this */\n" +
8492 " void *base_committed = VirtualAlloc (g_last->top_committed, commit_size,\n" +
8493 " MEM_COMMIT, PAGE_READWRITE);\n" +
8494 " /* Check returned pointer for consistency */\n" +
8495 " if (base_committed != g_last->top_committed)\n" +
8496 " goto sbrk_exit;\n" +
8497 " /* Assert postconditions */\n" +
8498 " assert ((unsigned) base_committed % g_pagesize == 0);\n" +
8499 "#ifdef TRACE\n" +
8500 " printf (\"Commit %p %d\\n\", base_committed, commit_size);\n" +
8501 "#endif\n" +
8502 " /* Adjust the regions commit top */\n" +
8503 " g_last->top_committed = (char *) base_committed + commit_size;\n" +
8504 " }\n" +
8505 " }\n" +
8506 " /* Adjust the regions allocation top */\n" +
8507 " g_last->top_allocated = (char *) g_last->top_allocated + allocate_size;\n" +
8508 " result = (char *) g_last->top_allocated - size;\n" +
8509 " /* Deallocation requested? */\n" +
8510 " } else if (size < 0) {\n" +
8511 " long deallocate_size = - size;\n" +
8512 " /* As long as we have a region to release */\n" +
8513 …ast->top_allocated - deallocate_size < (char *) g_last->top_reserved - g_last->reserve_size) {\n" +
8514 " /* Get the size to release */\n" +
8515 " long release_size = g_last->reserve_size;\n" +
8516 " /* Get the base address */\n" +
8517 " void *base_reserved = (char *) g_last->top_reserved - release_size;\n" +
8518 " /* Assert preconditions */\n" +
8519 " assert ((unsigned) base_reserved % g_regionsize == 0);\n" +
8520 " assert (0 < release_size && release_size % g_regionsize == 0); {\n" +
8521 " /* Release this */\n" +
8522 " int rc = VirtualFree (base_reserved, 0,\n" +
8523 " MEM_RELEASE);\n" +
8524 " /* Check returned code for consistency */\n" +
8525 " if (! rc)\n" +
8526 " goto sbrk_exit;\n" +
8527 "#ifdef TRACE\n" +
8528 " printf (\"Release %p %d\\n\", base_reserved, release_size);\n" +
8529 "#endif\n" +
8530 " }\n" +
8531 " /* Adjust deallocation size */\n" +
8532 " deallocate_size -= (char *) g_last->top_allocated - (char *) base_reserved;\n" +
8533 " /* Remove the old region from the list */\n" +
8534 " if (! region_list_remove (&g_last))\n" +
8535 " goto sbrk_exit;\n" +
8536 " } {\n") +
8538 " /* Compute the size to decommit */\n" +
8539 …ecommit = (char *) g_last->top_committed - ((char *) g_last->top_allocated - deallocate_size);\n" +
8540 " if (to_decommit >= g_my_pagesize) {\n" +
8541 " /* Compute the size to decommit */\n" +
8542 " long decommit_size = FLOOR (to_decommit, g_my_pagesize);\n" +
8543 " /* Compute the base address */\n" +
8544 " void *base_committed = (char *) g_last->top_committed - decommit_size;\n" +
8545 " /* Assert preconditions */\n" +
8546 " assert ((unsigned) base_committed % g_pagesize == 0);\n" +
8547 " assert (0 < decommit_size && decommit_size % g_pagesize == 0); {\n" +
8548 " /* Decommit this */\n" +
8549 " int rc = VirtualFree ((char *) base_committed, decommit_size,\n" +
8550 " MEM_DECOMMIT);\n" +
8551 " /* Check returned code for consistency */\n" +
8552 " if (! rc)\n" +
8553 " goto sbrk_exit;\n" +
8554 "#ifdef TRACE\n" +
8555 " printf (\"Decommit %p %d\\n\", base_committed, decommit_size);\n" +
8556 "#endif\n" +
8557 " }\n" +
8558 " /* Adjust deallocation size and regions commit and allocate top */\n" +
8559 " deallocate_size -= (char *) g_last->top_allocated - (char *) base_committed;\n" +
8560 " g_last->top_committed = base_committed;\n" +
8561 " g_last->top_allocated = base_committed;\n" +
8562 " }\n" +
8563 " }\n" +
8564 " /* Adjust regions allocate top */\n" +
8565 " g_last->top_allocated = (char *) g_last->top_allocated - deallocate_size;\n" +
8566 " /* Check for underflow */\n" +
8567 … if ((char *) g_last->top_reserved - g_last->reserve_size > (char *) g_last->top_allocated ||\n" +
8568 " g_last->top_allocated > g_last->top_committed) {\n" +
8569 " /* Adjust regions allocate top */\n" +
8570 " g_last->top_allocated = (char *) g_last->top_reserved - g_last->reserve_size;\n" +
8571 " goto sbrk_exit;\n" +
8572 " }\n" +
8573 " result = g_last->top_allocated;\n" +
8574 " }\n" +
8575 " /* Assert invariants */\n" +
8576 " assert (g_last);\n" +
8577 …ert ((char *) g_last->top_reserved - g_last->reserve_size <= (char *) g_last->top_allocated &&\n" +
8578 " g_last->top_allocated <= g_last->top_committed);\n" +
8579 …ert ((char *) g_last->top_reserved - g_last->reserve_size <= (char *) g_last->top_committed &&\n" +
8580 " g_last->top_committed <= g_last->top_reserved &&\n" +
8581 " (unsigned) g_last->top_committed % g_pagesize == 0);\n" +
8582 " assert ((unsigned) g_last->top_reserved % g_regionsize == 0);\n" +
8583 " assert ((unsigned) g_last->reserve_size % g_regionsize == 0);\n" +
8584 "\n" +
8585 "sbrk_exit:\n" +
8586 "#if defined (USE_MALLOC_LOCK) && defined (NEEDED)\n" +
8587 " /* Release spin lock */\n" +
8588 " slrelease (&g_sl);\n" +
8589 "#endif\n" +
8590 " return result;\n" +
8591 "}\n" +
8592 "\n" +
8593 "/* mmap for windows */\n" +
8594 "static void *mmap (void *ptr, long size, long prot, long type, long handle, long arg) {\n" +
8595 " static long g_pagesize;\n" +
8596 " static long g_regionsize;\n" +
8597 "#ifdef TRACE\n" +
8598 " printf (\"mmap %d\\n\", size);\n" +
8599 "#endif\n" +
8600 "#if defined (USE_MALLOC_LOCK) && defined (NEEDED)\n" +
8601 " /* Wait for spin lock */\n" +
8602 " slwait (&g_sl);\n" +
8603 "#endif\n" +
8604 " /* First time initialization */\n" +
8605 " if (! g_pagesize)\n" +
8606 " g_pagesize = getpagesize ();\n" +
8607 " if (! g_regionsize)\n" +
8608 " g_regionsize = getregionsize ();\n" +
8609 " /* Assert preconditions */\n" +
8610 " assert ((unsigned) ptr % g_regionsize == 0);\n" +
8611 " assert (size % g_pagesize == 0);\n" +
8612 " /* Allocate this */\n" +
8613 " ptr = VirtualAlloc (ptr, size,\n" +
8614 " MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE);\n" +
8615 " if (! ptr) {\n" +
8616 " ptr = (void *) MORECORE_FAILURE;\n" +
8617 " goto mmap_exit;\n" +
8618 " }\n" +
8619 " /* Assert postconditions */\n" +
8620 " assert ((unsigned) ptr % g_regionsize == 0);\n" +
8621 "#ifdef TRACE\n" +
8622 " printf (\"Commit %p %d\\n\", ptr, size);\n" +
8623 "#endif\n" +
8624 "mmap_exit:\n" +
8625 "#if defined (USE_MALLOC_LOCK) && defined (NEEDED)\n" +
8626 " /* Release spin lock */\n" +
8627 " slrelease (&g_sl);\n" +
8628 "#endif\n" +
8629 " return ptr;\n" +
8630 "}\n" +
8631 "\n" +
8632 "/* munmap for windows */\n" +
8633 "static long munmap (void *ptr, long size) {\n" +
8634 " static long g_pagesize;\n" +
8635 " static long g_regionsize;\n" +
8636 " int rc = MUNMAP_FAILURE;\n" +
8637 "#ifdef TRACE\n" +
8638 " printf (\"munmap %p %d\\n\", ptr, size);\n" +
8639 "#endif\n" +
8640 "#if defined (USE_MALLOC_LOCK) && defined (NEEDED)\n" +
8641 " /* Wait for spin lock */\n" +
8642 " slwait (&g_sl);\n" +
8643 "#endif\n" +
8644 " /* First time initialization */\n" +
8645 " if (! g_pagesize)\n" +
8646 " g_pagesize = getpagesize ();\n" +
8647 " if (! g_regionsize)\n" +
8648 " g_regionsize = getregionsize ();\n" +
8649 " /* Assert preconditions */\n" +
8650 " assert ((unsigned) ptr % g_regionsize == 0);\n" +
8651 " assert (size % g_pagesize == 0);\n" +
8652 " /* Free this */\n" +
8653 " if (! VirtualFree (ptr, 0,\n" +
8654 " MEM_RELEASE))\n" +
8655 " goto munmap_exit;\n" +
8656 " rc = 0;\n" +
8657 "#ifdef TRACE\n" +
8658 " printf (\"Release %p %d\\n\", ptr, size);\n" +
8659 "#endif\n" +
8660 "munmap_exit:\n" +
8661 "#if defined (USE_MALLOC_LOCK) && defined (NEEDED)\n" +
8662 " /* Release spin lock */\n" +
8663 " slrelease (&g_sl);\n" +
8664 "#endif\n" +
8665 " return rc;\n" +
8666 "}\n" +
8667 "\n" +
8668 "static void vminfo (CHUNK_SIZE_T *free, CHUNK_SIZE_T *reserved, CHUNK_SIZE_T *committed) {\n" +
8669 " MEMORY_BASIC_INFORMATION memory_info;\n" +
8670 " memory_info.BaseAddress = 0;\n" +
8671 " *free = *reserved = *committed = 0;\n" +
8672 " while (VirtualQuery (memory_info.BaseAddress, &memory_info, sizeof (memory_info))) {\n" +
8673 " switch (memory_info.State) {\n" +
8674 " case MEM_FREE:\n" +
8675 " *free += memory_info.RegionSize;\n" +
8676 " break;\n" +
8677 " case MEM_RESERVE:\n" +
8678 " *reserved += memory_info.RegionSize;\n" +
8679 " break;\n" +
8680 " case MEM_COMMIT:\n" +
8681 " *committed += memory_info.RegionSize;\n" +
8682 " break;\n" +
8683 " }\n" +
8684 " memory_info.BaseAddress = (char *) memory_info.BaseAddress + memory_info.RegionSize;\n" +
8685 " }\n" +
8686 "}\n" +
8687 "\n") +
8689 "static int cpuinfo (int whole, CHUNK_SIZE_T *kernel, CHUNK_SIZE_T *user) {\n" +
8690 " if (whole) {\n" +
8691 " __int64 creation64, exit64, kernel64, user64;\n" +
8692 " int rc = GetProcessTimes (GetCurrentProcess (),\n" +
8693 " (FILETIME *) &creation64,\n" +
8694 " (FILETIME *) &exit64,\n" +
8695 " (FILETIME *) &kernel64,\n" +
8696 " (FILETIME *) &user64);\n" +
8697 " if (! rc) {\n" +
8698 " *kernel = 0;\n" +
8699 " *user = 0;\n" +
8700 " return FALSE;\n" +
8701 " }\n" +
8702 " *kernel = (CHUNK_SIZE_T) (kernel64 / 10000);\n" +
8703 " *user = (CHUNK_SIZE_T) (user64 / 10000);\n" +
8704 " return TRUE;\n" +
8705 " } else {\n" +
8706 " __int64 creation64, exit64, kernel64, user64;\n" +
8707 " int rc = GetThreadTimes (GetCurrentThread (),\n" +
8708 " (FILETIME *) &creation64,\n" +
8709 " (FILETIME *) &exit64,\n" +
8710 " (FILETIME *) &kernel64,\n" +
8711 " (FILETIME *) &user64);\n" +
8712 " if (! rc) {\n" +
8713 " *kernel = 0;\n" +
8714 " *user = 0;\n" +
8715 " return FALSE;\n" +
8716 " }\n" +
8717 " *kernel = (CHUNK_SIZE_T) (kernel64 / 10000);\n" +
8718 " *user = (CHUNK_SIZE_T) (user64 / 10000);\n" +
8719 " return TRUE;\n" +
8720 " }\n" +
8721 "}\n" +
8722 "\n" +
8723 "#endif /* WIN32 */\n" +
8724 "\n" +
8725 "#endif // NDEBUG\n" +
8726 "\n" +
8727 "}; /* end of namespace KJS */\n");
8731 "ประเทศไทย\n" +
8732 "จากวิกิพีเดีย สารานุกรมเสรี\n" +
8733 "ไปที่: ป้ายบอกทาง, ค้นหา\n" +
8734 " \n" +
8735 "\n" +
8736 …ูกก่อกวนหลายครั้งติดต่อกัน การแก้ไขจากผู้ที่ไม่ได้ลงทะเบียน หรือผู้ใช้ใหม่ไม่สามารถทำได้ขณะนี้\n" +
8737 …ความเห็น เสนอข้อความ หรือขอให้ยกเลิกการป้องกันได้ในหน้าอภิปราย หรือลงทะเบียนโดยสร้างชื่อผู้ใช้\n" +
8738 " \n" +
8739 "วิกิพีเดีย:บทความคัดสรร\n" +
8740 "\n" +
8741 " \"ไทย\" เปลี่ยนทางมาที่นี่ สำหรับความหมายอื่น ดูที่ ไทย (แก้ความกำกวม)\n" +
8742 "\n" +
8743 "ราชอาณาจักรไทย\n" +
8744 "ธงชาติไทย ตราแผ่นดินของไทย\n" +
8745 "ธงชาติ ตราแผ่นดิน\n" +
8746 "คำขวัญ: ชาติ ศาสนา พระมหากษัตริย์\n" +
8747 "เพลงชาติ: เพลงชาติไทย\n" +
8748 "แผนที่แสดงที่ตั้งของประเทศไทย\n" +
8749 "เมืองหลวง กรุงเทพมหานคร\n" +
8750 "13°44′N 100°30′E\n" +
8751 "เมืองใหญ่สุด กรุงเทพมหานคร\n" +
8752 "ภาษาราชการ ภาษาไทย\n" +
8753 "รัฐบาล เผด็จการทหาร\n" +
8754 " - ประมุขแห่งรัฐ พระบาทสมเด็จพระปรมินทรมหาภูมิพลอดุลยเดช\n" +
8755 " - นายกรัฐมนตรี พลเอกสุรยุทธ์ จุลานนท์\n" +
8756 " - ประธานคณะมนตรีความมั่นคงแห่งชาติ พลอากาศเอก ชลิต พุกผาสุข (รักษาการ)\n" +
8757 "สถาปนาเป็น\n" +
8758 "• สุโขทัย\n" +
8759 "• กรุงศรีอยุธยา\n" +
8760 "• กรุงธนบุรี\n" +
8761 "• กรุงรัตนโกสินทร์ \n" +
8762 "พ.ศ. 1781–1911\n" +
8763 "1893–2310\n" +
8764 "2310–6 เมษายน 2325\n" +
8765 "6 เมษายน 2325–ปัจจุบัน\n" +
8766 "เนื้อที่\n" +
8767 " - ทั้งหมด\n" +
8768 " \n" +
8769 " - พื้นน้ำ (%) \n" +
8770 "514,000 กม.² (อันดับที่ 49)\n" +
8771 "198,457 ไมล์² \n" +
8772 "0.4%\n" +
8773 "ประชากร\n" +
8774 " - 2548 ประมาณ\n" +
8775 " - 2543\n" +
8776 " - ความหนาแน่น \n" +
8777 "62,418,054 (อันดับที่ 19)\n" +
8778 "60,916,441\n" +
8779 "122/กม² (อันดับที่ 59)\n" +
8780 "{{{population_densitymi²}}}/ไมล์² \n" +
8781 "GDP (PPP)\n" +
8782 " - รวม\n" +
8783 " - ต่อประชากร 2548 ค่าประมาณ\n" +
8784 "$559.5 billion (อันดับที่ 21)\n" +
8785 "$8,542 (อันดับที่ 72)\n" +
8786 "HDI (2546) 0.778 (อันดับที่ 73) – ปานกลาง\n" +
8787 "สกุลเงิน บาท (฿) (THB)\n" +
8788 "เขตเวลา (UTC+7)\n" +
8789 "รหัสอินเทอร์เน็ต .th\n" +
8790 "รหัสโทรศัพท์ +66\n" +
8791 "\n" +
8792 …เลเซีย ทิศตะวันตกติดทะเลอันดามันและพม่า และทิศเหนือติดพม่าและลาว โดยมีแม่น้ำโขงกั้นเป็นบางช่วง\n" +
8793 "\n" +
8794 …ระชาชาติ เอเปค และ อาเซียน มีศูนย์รวมการปกครองอยู่ที่ กรุงเทพมหานคร ซึ่งเป็นเมืองหลวงของประเทศ\n" +
8795 "\n" +
8796 …ูมิพลอดุลยเดช ทรงเป็นพระมหากษัตริย์ที่ครองราชย์ ในฐานะประมุขแห่งรัฐ ยาวนานที่สุดในโลกถึง 60 ปี\n" +
8797 "\n" +
8798 "\n" +
8799 "เนื้อหา\n" +
8800 "[ซ่อน]\n" +
8801 "\n" +
8802 " * 1 ประวัติศาสตร์\n" +
8803 " o 1.1 ชื่อประเทศไทย\n" +
8804 " * 2 การเมืองการปกครอง\n" +
8805 " o 2.1 เขตการปกครอง\n" +
8806 " o 2.2 เมืองใหญ่ / จังหวัดใหญ่\n" +
8807 " * 3 ภูมิอากาศและภูมิประเทศ\n" +
8808 " o 3.1 ภูมิประเทศ\n" +
8809 " o 3.2 ภูมิอากาศ\n" +
8810 " * 4 เศรษฐกิจ\n" +
8811 " o 4.1 เศรษฐกิจหลักของประเทศ\n" +
8812 " o 4.2 การคมนาคม\n" +
8813 " o 4.3 การสื่อสาร\n" +
8814 " * 5 สังคม\n" +
8815 " o 5.1 ชนชาติ\n" +
8816 " o 5.2 ศาสนา\n" +
8817 " o 5.3 การศึกษา\n" +
8818 " o 5.4 ภาษา\n" +
8819 " o 5.5 ศิลปะและวัฒนธรรม\n" +
8820 " o 5.6 กีฬา\n" +
8821 " o 5.7 วันสำคัญ\n" +
8822 " * 6 ลำดับที่สำคัญ\n" +
8823 " * 7 อ้างอิง\n" +
8824 " * 8 แหล่งข้อมูลอื่น\n" +
8825 "\n" +
8826 "ประวัติศาสตร์\n" +
8827 "\n" +
8828 " ดูบทความหลักที่ ประวัติศาสตร์ไทย\n" +
8829 "\n" +
8830 …ียกรุงศรีอยุธยาเป็นครั้งที่สองในปี พ.ศ. 2310 พระเจ้าตากสินจึงได้ย้ายราชธานีมาอยู่ที่กรุงธนบุรี\n" +
8831 "\n" +
8832 …ซึ่งเป็นการยึดอำนาจจากรัฐบาลรักษาการ หลังจากได้มีการยุบสภาผู้แทนราษฎรเมื่อเดือนกุมภาพันธ์ 2549\n" +
8833 "\n" +
8834 "ชื่อประเทศไทย\n" +
8835 "\n" +
8836 …Thailand\" อย่างในปัจจุบัน อย่างไรก็ตาม ชื่อ สยาม ยังเป็นที่รู้จักแพร่หลายทั้งในและต่างประเทศ.\n" +
8837 "\n" +
8838 "การเมืองการปกครอง\n" +
8839 "\n" +
8840 …ัญญัติ ได้แก่ สภานิติบัญญัติแห่งชาติ และฝ่ายตุลาการ คือ ศาลยุติธรรม ศาลรัฐธรรมนูญ และศาลปกครอง\n" +
8841 "\n" +
8842 …ั้งโดยคณะมนตรีความมั่นคงแห่งชาติ หลังเกิดเหตุการณ์รัฐประหารเมื่อคืนวันที่ 19 กันยายน พ.ศ. 2549\n" +
8843 "\n" +
8844 "เขตการปกครอง\n" +
8845 "\n" +
8846 … เทศบาล และองค์การบริหารส่วนตำบล ส่วน'สุขาภิบาล'นั้นถูกยกฐานะไปเป็นเทศบาลทั้งหมดในปี พ.ศ. 2542\n" +
8847 "\n" +
8848 " รายชื่อจังหวัดทั้งหมดดูเพิ่มเติมที่ จังหวัดในประเทศไทย\n" +
8849 "\n" +
8850 "เมืองใหญ่ / จังหวัดใหญ่\n" +
8851 "ประเทศไทย จังหวัดในประเทศไทย\n" +
8852 "ประเทศไทย จังหวัดในประเทศไทย\n" +
8853 "กรุงเทพมหานครริมแม่น้ำเจ้าพระยา\n" +
8854 "กรุงเทพมหานครริมแม่น้ำเจ้าพระยา\n" +
8855 "\n" +
8856 …่าง โดยดูจากจำนวนประชากรในเขตเทศบาลและกรุงเทพมหานคร ซึ่งจะแสดงประชากรในเขตเมืองได้อย่างแท้จริง\n" +
8857 "อันดับ เมือง / เทศบาล จำนวนประชากร จังหวัด\n" +
8858 "1 กรุงเทพมหานคร 6,121,672 กรุงเทพมหานคร\n" +
8859 "2 นนทบุรี 266,941 นนทบุรี\n" +
8860 "3 ปากเกร็ด 167,138 นนทบุรี\n" +
8861 "4 หาดใหญ่ 157,678 สงขลา\n" +
8862 "5 เชียงใหม่ 150,805 เชียงใหม่\n" +
8863 "6 นครราชสีมา 149,938 นครราชสีมา\n" +
8864 "7 อุดรธานี 142,670 อุดรธานี\n" +
8865 "8 สุราษฎร์ธานี 124,665 สุราษฎร์ธานี\n" +
8866 "9 ขอนแก่น 121,283 ขอนแก่น\n" +
8867 "10 นครศรีธรรมราช 106,293 นครศรีธรรมราช\n" +
8868 "\n" +
8869 "นอกจากนี้ยังมีการเรียงลำดับประชากรตามจังหวัดได้ดังต่อไปนี้\n" +
8870 "อันดับ จังหวัด จำนวนประชากร ภาค\n" +
8871 "1 กรุงเทพมหานคร 6,121,672 ภาคกลาง\n" +
8872 "2 นครราชสีมา 2,546,763 ภาคตะวันออกเฉียงเหนือ\n" +
8873 "3 อุบลราชธานี 1,774,808 ภาคตะวันออกเฉียงเหนือ\n" +
8874 "4 ขอนแก่น 1,747,542 ภาคตะวันออกเฉียงเหนือ\n" +
8875 "5 เชียงใหม่ 1,650,009 ภาคเหนือ\n" +
8876 "6 บุรีรัมย์ 1,531,430 ภาคตะวันออกเฉียงเหนือ\n" +
8877 "7 อุดรธานี 1,523,802 ภาคตะวันออกเฉียงเหนือ\n" +
8878 "8 นครศรีธรรมราช 1,504,420 ภาคใต้\n" +
8879 "9 ศรีสะเกษ 1,443,975 ภาคตะวันออกเฉียงเหนือ\n" +
8880 "10 สุรินทร์ 1,374,700 ภาคตะวันออกเฉียงเหนือ\n" +
8881 "\n" +
8882 …ั้งหมดที่ เมืองใหญ่ของประเทศไทยเรียงตามจำนวนประชากร และ จังหวัดในประเทศไทยเรียงตามจำนวนประชากร\n" +
8883 "\n" +
8884 "ภูมิอากาศและภูมิประเทศ\n" +
8885 "\n" +
8886 "ภูมิประเทศ\n" +
8887 "ประเทศไทย สภาพทางภูมิศาสตร์\n" +
8888 "ประเทศไทย สภาพทางภูมิศาสตร์\n" +
8889 "\n" +
8890 …จ้าพระยา ซึ่งสายน้ำไหลลงสู่อ่าวไทย ภาคใต้มีจุดที่แคบลง ณ คอคอดกระแล้วขยายใหญ่เป็นคาบสมุทรมลายู\n" +
8891 "\n" +
8892 " * เมื่อเปรียบเทียบพื้นที่ของประเทศไทย กับ ประเทศอื่น จะได้ดังนี้\n" +
8893 " o ประเทศพม่า ใหญ่กว่าประเทศไทยประมาณ 1.3 เท่า\n" +
8894 " o ประเทศอินโดนีเซีย ใหญ่กว่าประมาณ 3.7 เท่า\n" +
8895 " o ประเทศอินเดีย ใหญ่กว่าประมาณ 6.4 เท่า\n" +
8896 " o ประเทศจีน และ สหรัฐอเมริกา ใหญ่กว่าประมาณ 19 เท่า\n" +
8897 " o ประเทศรัสเซีย ใหญ่กว่าประมาณ 33 เท่า\n" +
8898 " o ขนาดใกล้เคียงกับ ประเทศฝรั่งเศส ประเทศสวีเดน และ ประเทศสเปน\n" +
8899 "\n" +
8900 …ี่ 26 ธันวาคม พ.ศ. 2547 ได้มีเหตุการณ์คลื่นสึนามิเกิดขึ้นก่อความเสียหายในเขตภาคใต้ของประเทศไทย\n" +
8901 "\n" +
8902 "ภูมิอากาศ\n" +
8903 "\n" +
8904 …าคม อากาศแห้ง และหนาวเย็นจากลมมรสุมตะวันออกเฉียงเหนือ ยกเว้นภาคใต้ที่มีอากาศร้อนชื้นตลอดทั้งปี\n" +
8905 "\n" +
8906 "เศรษฐกิจ\n" +
8907 "\n" +
8908 "เศรษฐกิจหลักของประเทศ\n" +
8909 "\n" +
8910 …30.4 พันล้านบาท ส่งออกมูลค่า 78.1 พันล้านเหรียญสหรัฐ ในขณะที่นำเข้า 74.3 พันล้านเหรียญสหรัฐ[3]\n" +
8911 "ภาพพันธุ์ข้าวจากกรมวิชาการเกษตร\n" +
8912 "ภาพพันธุ์ข้าวจากกรมวิชาการเกษตร\n" +
8913 "ภาพยางพาราจากกรมวิชาการเกษตร\n" +
8914 "ภาพยางพาราจากกรมวิชาการเกษตร\n" +
8915 "\n" +
8916 …การประมงทางทะเล ปี 2549 ไทยมีการส่งออกกุ้งไปสหรัฐฯ 177,717.29 ตัน มูลค่า 45,434.57 ล้านบาท [5]\n" +
8917 "\n" +
8918 ….28 ล้านคัน ดีบุก 694 ตัน ก๊าซธรรมชาติ 789 พันล้านลูกบาศก์ฟุต น้ำมันดิบ]] 31.1 ล้านบาร์เรล [6]\n" +
8919 "เกาะพีพี สถานท่องเที่ยวที่สำคัญแห่งหนึ่งของประเทศ\n" +
8920 "เกาะพีพี สถานท่องเที่ยวที่สำคัญแห่งหนึ่งของประเทศ\n" +
8921 "\n" +
8922 …7] สถานที่ท่องเที่ยวที่สำคัญได้แก่ กรุงเทพมหานคร พัทยา ภาคใต้ฝั่งทะเลอันดามัน จังหวัดเชียงใหม่\n" +
8923 "\n" +
8924 "การคมนาคม\n" +
8925 "\n" +
8926 "ดูบทความหลัก การคมนาคมในประเทศไทย\n" +
8927 "\n" +
8928 …อเตอร์ไซค์รับจ้าง และ รถตุ๊กตุ๊ก ในบางพื้นที่ ที่อยู่ริมน้ำจะมีเรือรับจ้าง และแพข้ามฟาก บริการ\n" +
8929 "รถไฟฟ้าบีทีเอส สถานีอโศก\n" +
8930 "รถไฟฟ้าบีทีเอส สถานีอโศก\n" +
8931 "\n" +
8932 …ี่ 29 กันยายน พ.ศ. 2549 ทดแทนท่าอากาศยานนานาชาติกรุงเทพ (ดอนเมือง) ที่เปิดใช้งานมานานถึง 92 ปี\n" +
8933 "\n" +
8934 "ส่วนการคมนาคมทางน้ำ ประเทศไทยมีท่าเรือหลักๆ คือ ท่าเรือกรุงเทพ(คลองเตย) และท่าเรือแหลมฉบัง\n" +
8935 "\n" +
8936 "การสื่อสาร\n" +
8937 "\n" +
8938 …เทศไทยมีโทรศัพท์พื้นฐาน 7.035 ล้านหมายเลข (2548) และโทรศัพท์มือถือ 27.4 ล้านหมายเลข (2548) [8]\n" +
8939 …ื่นเอเอ็ม 204 สถานี และ คลื่นสั้น 6 สถานี (2542) โดยมีจำนวนผู้ใช้วิทยุ 13.96 ล้านคน (2540) [8]\n" +
8940 …ยู่ในกรุงเทพ) มีสถานีเครือข่ายทั้งหมด 111 สถานี และจำนวนผู้ใช้โทรทัศน์ 15.19 ล้านคน (2540) [8]\n" +
8941 " * รหัสโดเมนอินเทอร์เน็ตใช้รหัส th\n" +
8942 "\n" +
8943 "สังคม\n" +
8944 "วัดพระศรีรัตนศาสดาราม กรุงเทพมหานคร\n" +
8945 "วัดพระศรีรัตนศาสดาราม กรุงเทพมหานคร\n" +
8946 "\n" +
8947 "ชนชาติ\n" +
8948 "\n" +
8949 …ชาวระแดว์ ชาวข่า ชาวขมุ ซึ่งมีในปัจจุบันก็มีความสำคัญมาก ต่อวิถีชีวิต และวัฒนธรรมไทยในปัจจุบัน\n" +
8950 "\n" +
8951 "ประชากรชาวไทย 75% ชาวไทยเชื้อสายจีน 14% และอื่นๆ 11% [8]\n" +
8952 "\n" +
8953 " ดูเพิ่มที่ ชาวไทย\n" +
8954 "\n" +
8955 "ศาสนา\n" +
8956 "พระพุทธชินราช วัดพระศรีรัตนมหาธาตุวรมหาวิหาร จังหวัดพิษณุโลก\n" +
8957 "พระพุทธชินราช วัดพระศรีรัตนมหาธาตุวรมหาวิหาร จังหวัดพิษณุโลก\n" +
8958 "\n" +
8959 …ิสลามประมาณร้อยละ 4 (ส่วนใหญ่เป็นชาวไทยทางภาคใต้ตอนล่าง) ศาสนาคริสต์และศาสนาอื่นประมาณร้อยละ 1\n" +
8960 "\n" +
8961 " ดูเพิ่มที่ พระพุทธศาสนาในประเทศไทย\n" +
8962 "\n" +
8963 "การศึกษา\n" +
8964 "\n" +
8965 …ือกศึกษาต่อสายวิชาชีพ ในวิทยาลัยเทคนิค หรือพาณิชยการ หรือเลือกศึกษาต่อในสถาบันทางทหารหรือตำรวจ\n" +
8966 "\n" +
8967 …โรงเรียนรัฐบาลและมหาวิทยาลัยรัฐบาล จะเสียค่าเล่าเรียนน้อยกว่า โรงเรียนเอกชนและมหาวิทยาลัยเอกชน\n" +
8968 "\n" +
8969 " ดูเพิ่มที่ รายชื่อสถาบันอุดมศึกษาในประเทศไทย\n" +
8970 "\n" +
8971 "ภาษา\n" +
8972 "\n" +
8973 " ดูบทความหลักที่ ภาษาในประเทศไทย\n" +
8974 "\n" +
8975 …ุโขทัยโดย พ่อขุนรามคำแหงมหาราช ส่วนภาษาอื่นที่มีการใช้อยู่บ้าง เช่น ภาษาอังกฤษ ภาษาจีน เป็นต้น\n" +
8976 "\n" +
8977 "ศิลปะและวัฒนธรรม\n" +
8978 "พระที่นั่งไอศวรรย์ทิพย์อาสน์ พระราชวังบางปะอิน จังหวัดพระนครศรีอยุธยา\n" +
8979 "พระที่นั่งไอศวรรย์ทิพย์อาสน์ พระราชวังบางปะอิน จังหวัดพระนครศรีอยุธยา\n" +
8980 "\n" +
8981 …ิลปวัฒนธรรมเพื่อนบ้านอยู่บ้าง แต่ด้วยการสืบทอดและการสร้างสรรค์ใหม่ ทำให้ศิลปะไทยมีเอกลักษณ์สูง\n" +
8982 "\n" +
8983 …ยโบราณ งานจิตรกรรมไทยยังเกี่ยวข้องกับงานศิลปะแขนงอื่นๆ เช่น งานลงรักปิดทอง ภาพวาดพระบฏ เป็นต้น\n" +
8984 …้วจึงนำไปหล่อโลหะ เมื่อเทียบกับประติมากรรมศิลาในยุคก่อนนั้น งานสำริดนับว่าอ่อนช้อยงดงามกว่ามาก\n" +
8985 …นเรือนไทย โบสถ์ วัด และปราสาทราชวัง ซึ่งล้วนแต่สร้างขึ้นให้เหมาะสมกับสภาพอากาศและการใช้สอยจริง\n" +
8986 "\n" +
8987 " ดูเพิ่มที่ ศิลปะไทย\n" +
8988 "\n" +
8989 "กีฬา\n" +
8990 "ราชมังคลากีฬาสถาน การกีฬาแห่งประเทศไทย\n" +
8991 "ราชมังคลากีฬาสถาน การกีฬาแห่งประเทศไทย\n" +
8992 "\n" +
8993 …และ ตะกร้อ แม้จะมีความนิยมไม่เท่ากีฬาทั่วไป แต่ยังมีการเล่นโดยทั่วไปรวมถึงการเปิดสอนในโรงเรียน\n" +
8994 "\n" +
8995 …ศไทยเป็นตัวแทนจัดงานเอเชียนเกมส์ 4 ครั้ง และซีเกมส์ ทั้งหมด 5 ครั้ง โดยจัดครั้งแรกที่ประเทศไทย\n" +
8996 "\n" +
8997 "นักกีฬาไทยที่มีชื่อเสียงมาก ได้แก่\n" +
8998 "\n" +
8999 " * นักมวย - เขาทราย แกแล็คซี่, สด จิตรลดา, สามารถ พยัคฆ์อรุณ, สมรักษ์ คำสิงห์\n" +
9000 " * นักเทนนิส - ภราดร ศรีชาพันธุ์, แทมมารีน ธนสุกาญจน์, ดนัย อุดมโชค\n" +
9001 " * นักว่ายน้ำ - รัฐพงษ์ ศิริสานนท์(ฉลามนุ้ก), ต่อวัย เสฎฐโสธร, ต่อลาภ เสฎฐโสธร\n" +
9002 " * นักฟุตบอล - ปิยะพงษ์ ผิวอ่อน, เกียรติศักดิ์ เสนาเมือง\n" +
9003 " * นักสนุกเกอร์ - ต๋อง ศิษย์ฉ่อย\n" +
9004 " * นักกรีฑา - เรวดี ศรีท้าว\n" +
9005 " * นักเทควันโด - เยาวภา บุรพลชัย\n" +
9006 " * นักยกน้ำหนัก - อุดมพร พลศักดิ์, ปวีณา ทองสุก\n" +
9007 " * นักกอล์ฟ - ธงชัย ใจดี\n" +
9008 "\n" +
9009 "วันสำคัญ\n" +
9010 "\n" +
9011 …ทศไทยตรงกับวันที่ 5 ธันวาคม เป็น ตามวันพระราชสมภพ ของพระบาทสมเด็จพระเจ้าอยู่หัว ภูมิพลอดุลยเดช\n" +
9012 "\n" +
9013 " ดูบทความหลักที่ วันสำคัญในประเทศไทย\n" +
9014 "\n" +
9015 "ลำดับที่สำคัญ\n" +
9016 "\n" +
9017 …พระปรมินทรมหาภูมิพลอดุลยเดช เป็นพระมหากษัตริย์ที่ครองราชย์ในฐานะประมุขแห่งรัฐที่นานที่สุดในโลก\n" +
9018 " * กรุงเทพฯ เป็นเมืองหลวงที่มีชื่อยาวที่สุดในโลก (169 ตัวอักษร)\n" +
9019 …* ดัชนีเศรษฐกิจของประเทศไทย อยู่อันดับที่ 71 จาก 155 เขตเศรษฐกิจ ตาม Index of Economic Freedom\n" +
9020 …องสหรัฐเมื่อ พ.ศ. 2544 ว่าเป็นเมืองที่น่าอยู่สำหรับผู้สูงอายุชาวอเมริกันอันดับที่ 7 ของโลก [9]\n" +
9021 " * Growth Competitiveness Index Ranking พ.ศ. 2546 อยู่อันดับที่ 34 จาก 104 [10]\n" +
9022 " * ตึกใบหยก 2 เป็นตึกที่สูงที่สุดในประเทศไทย และสูงเป็นอันดับ 30 ของโลก พ.ศ. 2549\n" +
9023 "\n" +
9024 "อ้างอิง\n" +
9025 "\n" +
9026 " 1. ↑ 4th edition \"ANKOR an introduction to the temples\" Dawn Rooney ISBN: 962-217-683-6\n" +
9027 …ภาษาฝรั่งเศส เอกสารระหว่างประเทศจะใช้ภาษาฝรั่งเศสเป็นหลัก รวมถึงหนังสือเดินทางไทยรุ่นแรกๆ ด้วย\n" +
9028 " 3. ↑ ดัชนีเศรษฐกิจประเทศไทย จากเว็บไซต์ธนาคารแห่งประเทศไทย\n" +
9029 …นศูนย์กลางข้าวโลก โดย เทคโนโลยีชาวบ้าน มติชน วันที่ 01 มิถุนายน พ.ศ. 2550 ปีที่ 19 ฉบับที่ 408\n" +
9030 " 5. ↑ http://www.thairath.co.th/news.php?section=agriculture&content=52868\n" +
9031 " 6. ↑ ผลผลิตของประเทศไทย จากเว็บไซต์ธนาคารแห่งประเทศไทย\n" +
9032 " 7. ↑ ข้อมูลการท่องเที่ยว จากการท่องเที่ยวแห่งประเทศไทย (ข้อมูลเป็นไฟล์เอกเซล)\n" +
9033 " 8. ↑ 8.0 8.1 8.2 8.3 รายละเอียดประเทศไทยจากเว็บซีไอเอ\n" +
9034 " 9. ↑ http://207.5.46.81/tat_news/detail.asp?id=963\n" +
9035 " 10. ↑ ข้อมูลจาก Webforum.org พ.ศ. 2546\n" +
9036 "\n" +
9037 "แหล่งข้อมูลอื่น\n" +
9038 "Commons\n" +
9039 "คอมมอนส์ มีภาพและสื่ออื่นๆ เกี่ยวกับ:\n" +
9040 "ประเทศไทย\n" +
9041 "ฟลิคเกอร์\n" +
9042 "ฟลิคเกอร์ มีรูปภาพเกี่ยวกับ: ประเทศไทย\n" +
9043 "\n" +
9044 " * รัฐบาลไทย\n" +
9045 " * การท่องเที่ยวแห่งประเทศไทย\n" +
9046 " * ประเทศไทยศึกษา ห้องสมุดรัฐสภา สหรัฐอเมริกา\n" +
9047 " * พจนานุกรมท่องเที่ยวไทย\n" +
9048 " * แผนที่ประเทศไทย Longdo Map\n";
9120 if ("^]-\n\\".indexOf(c) == -1) {