Posts

Showing posts from February 12, 2019

Why doesn't g++ optimize local constexpr array access?

Image
1 I have following c++ code: inline int choose(int i){ static constexpr int arr={1,3,3,2,4,1,4}; return arr[i]; } void f(int); int main(){ for(int i=0;i<5;i++){ f(choose(i)); } } When I compile this with g++ 8.2 with option -O3, it produces well-optimized asm code. However, when I change the second line from static constexpr to constexpr , which should be semantically the same, it no longer optimizes array access, and produces somewhat inefficient asm code. Does anyone have any idea why this happens? c++ g++ compiler-optimization share | improve this question asked Nov 26 '18 at 13:45 ...

deleteAllFromRealm(RealmList : This method is only available in managed mode

Image
0 Android Studio 3.2. , Realm 4.1.0 I need to delete all items in list from Realm. My snippet: public static RealmList<Merchant> getMerchantsRealmList() { Realm realm = Realm.getDefaultInstance(); try { RealmResults<Merchant> realmResults = realm.where(Merchant.class).findAll(); RealmList<Merchant> realmList = new RealmList<>(); realmList.addAll(realmResults.subList(0, realmResults.size())); return realmList; } finally { realm.close(); } } public static void updateMerchantList(final List<Merchant> thatMerchantsList) { Realm realm = Realm.getDefaultInstance(); try { realm.executeTransaction(new Realm.Transaction() { @Overr...