惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security @ Cisco Blogs
The Last Watchdog
The Last Watchdog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
aimingoo的专栏
aimingoo的专栏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
PCI Perspectives
PCI Perspectives
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LangChain Blog
B
Blog RSS Feed
小众软件
小众软件
N
News | PayPal Newsroom
Attack and Defense Labs
Attack and Defense Labs
Microsoft Azure Blog
Microsoft Azure Blog
V
Vulnerabilities – Threatpost
The Hacker News
The Hacker News
T
Tor Project blog
A
Arctic Wolf
Jina AI
Jina AI
Hacker News: Ask HN
Hacker News: Ask HN
F
Fortinet All Blogs
Cloudbric
Cloudbric
S
Secure Thoughts
L
LINUX DO - 热门话题
博客园 - 司徒正美
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security Affairs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
J
Java Code Geeks
P
Privacy International News Feed
AWS News Blog
AWS News Blog
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
AI
AI
O
OpenAI News
C
Cyber Attacks, Cyber Crime and Cyber Security
K
Kaspersky official blog
T
The Blog of Author Tim Ferriss
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
T
Tenable Blog
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
S
SegmentFault 最新的问题

博客园 - begincsdn

C# 自定义光标使用的常见方法 二叉树的递归遍历以及非递归遍历(一)----先序遍历(转) Pentium指令的执行周期数[转] 计算机图形学 -- 光栅图形学扫描线填充多边形[转] 推荐一个跨平台内存分配器【转载】 开源几何计算数学库 C++中固定长度短字符串比较是否相同,忽略大小写比对时的小技巧 二维图形变换公式推导---------旋转变换 .NET 漫淡(一) --- 需要充分认识的应用程序域-AppDomain Gerber 文件格式(一):RS-274X 语法 SCRUM 系列之一 ----- 认识SRCUM GERBER文件格式简介 迷思微软两大框架的RTTI(Run-Time Type Identification) Remoting中,关于获取某接口派生的自定义属性(CustomAttribute)的问题 让你的VS。NET2003可以调试ASP服务器脚本。 UNION,EXISTS,IN等在SQL语句中的灵活应用和场境的选择。 欢迎大家加入我申请的QQ群。 客户端独立弹出详细的实现过程 - begincsdn - 博客园 Microsoft.Visual.Studio..NET.2005.预发行版 EMULE下载
几何图形库-GEOS使用示例(1)
begincsdn · 2012-07-22 · via 博客园 - begincsdn
以下代码是可以正确执行的,但唯一不足的是,单线程和多线程的执行效率几乎相同。究竟是什么原因还没搞清楚。
 
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/thread.hpp>

#include <geos/geos.h>
#include <vector>
#include "macros.h"
#include "threads.h"

using namespace std;

#pragma comment(lib,LIB_XD("geos_3_35"))

typedef boost::thread THREAD;

typedef boost::mutex MUTEX;
typedef Coordinate PT;

typedef boost::thread * PTHREAD;

int MAX_COUNT = 2;
int currentIndex = 0;

MUTEX mm;

void Union()
{  
    GeometryFactory factory;
    CoordinateArraySequenceFactory csf;

    CoordinateSequence* cs1 = csf.create(5,2);
    cs1->setAt(PT(0,0,0),0);
    cs1->setAt(PT(1,0,0),1);
    cs1->setAt(PT(1,1,0),2);
    cs1->setAt(PT(0,1,0),3);
    cs1->setAt(PT(0,0,0),4);
    LinearRing* ring1 = factory.createLinearRing(cs1);
    Geometry* p1 = factory.createPolygon(ring1,NULL);

    CoordinateSequence* cs2 = csf.create(5,2);
    cs2->setAt(PT(4,4,0),0);
    cs2->setAt(PT(4,5,0),1);
    cs2->setAt(PT(5,5,0),2);
    cs2->setAt(PT(5,4,0),3);
    cs2->setAt(PT(4,4,0),4);

    LinearRing * ring2 = factory.createLinearRing(cs2);
    Geometry* p2 = (factory.createPolygon(ring2,NULL));
    
    int index = 0;
    while(index < MAX_COUNT)
    {
        {
            LOCK(mm);
            index = ++currentIndex;
        }
        if(index % 1000 == 0) cout << "count " << index << endl;
        Geometry* poly = p1->Union(p2);
        //int number = poly->getNumGeometries();
        delete poly;
    }

    delete ring1;
    delete ring2;
}

int main(int argc, char* argv[])
{
    PTHREAD threads[8];
    clock_t start, finish;  
    start = clock();  
    bool enabledThreadCount = 8;
    for(int i = 0; i < enabledThreadCount ; i ++)
    {
        boost::thread * t = new boost::thread(&Union);
        threads[i] = t;
    }

    for(int i =0; i < enabledThreadCount ; i++)
    {
        threads[i]->join();
        delete threads[i];
    }
    
    finish = clock();
    cout << "该程序运行时间为" << ((double)(finish - start)) / CLOCKS_PER_SEC << endl;
    int pause;
    cin >> pause;
    return 0;
}