简体   繁体   English

在C ++中将REST API连接代码移植到Android NDK

[英]Porting REST API connection code to Android NDK in c++

I have an Android application in the market which connects and send POST and GET queries to a REST API, and then stores the results in a DB which are then queries and displayed in an appropriate manner in the application. 我在市场上有一个Android应用程序,它将POST和GET查询连接并发送到REST API,然后将结果存储在DB中,然后查询并以适当的方式显示在应用程序中。

I'm interested in speeding up the application and have noticed quite a lot of lag between the time of receiving the data back from the api and the data being ready to use. 我对加速应用程序感兴趣,并注意到从api接收数据和准备使用的数据之间存在很多延迟。 I'd like to investigate if and how I can write similar code in c++ using the NDK to connect to the REST API, process the results and store in a DB or raise an error. 我想研究是否以及如何使用NDK在c ++中编写类似的代码来连接到REST API,处理结果并存储在数据库中或引发错误。 I've no previous c++ experience and need to know firstly if I can access the same DB in the C++ as the Java, secondly if there are any other caveats which I should be aware of? 我没有以前的c ++经验,并且首先需要知道我是否可以像使用Java一样访问C ++中的相同数据库,其次如果还有其他需要注意的注意事项?

Also I guess I should ask - is it worth doing this? 我想我也应该问 - 这是值得做的吗? Will I notice any difference? 我会注意到有什么不同吗?

Any links to similar code, or an overview of where I should look to get started in c++ would be greatly appreciated. 任何指向类似代码的链接,或者我应该在c ++中开始的概述将非常感激。

I'm doing the EXACT same thing, and trust me: if you have no previous C++ experience, this might be a bit too costly for little benefit. 我在做同样事情,相信我:如果你没有以前的C ++的经验,这可能是有点太昂贵了一点好处。

In my case, after some profiling, I reordered things around and had an initial jump in performance only by dropping DOM and using SAX. 在我的情况下,经过一些分析后,我重新排序了一些东西,只是通过删除DOM和使用SAX来获得性能的初步提升。 All the rest is only making things marginally better, like processing the response while packets are still being transmitted (ie not wait for the full response to start processing), and multiplexing requests on the same thread instead of starting a new thread for each. 所有其余的只是使事情略微好转,比如在数据包仍在传输时处理响应(即不等待开始处理的完整响应),并在同一线程上复用请求而不是为每个线程启动新线程。

What you should be looking for in Google is POSIX sockets, HTTP and REST codes, if you wish to do it all by hand. 如果您希望手动完成,那么您在Google中应该寻找的是POSIX套接字,HTTP和REST代码。 A better option might be using CURL or something similar for the Socket/HTTP part. 更好的选择可能是对套接字/ HTTP部分使用CURL或类似的东西。 I did it all myself, but only because I have already done this a few times. 我自己做了这一切,但仅仅因为我已经做了几次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM